Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "Rus");
- bool isNotCorrect = false;
- int n, i;
- int array[100];
- cout << "Введите колличество элементов в массиве\n";
- do {
- cin >> n;
- if (cin.fail()) {
- isNotCorrect = true;
- cout << "Данные введены неккоректно\n\n";
- cin.clear();
- while (cin.get() != '\n');
- }
- else {
- for (i = 1; i <= n; ++i) {
- do {
- cout << "Введите " << i << " элемент массива\n";
- cin >> array[i];
- if (cin.fail()) {
- isNotCorrect = true;
- cout << "Данные введены неккоректно\n\n";
- cin.clear();
- while (cin.get() != '\n');
- }
- else {
- isNotCorrect = false;
- }
- } while (isNotCorrect);
- }
- }
- } while (isNotCorrect);
- cout << "Вывод на экран: \n";
- for (i = 1; i <= n; ++i) {
- if (i % 2 == 1) {
- cout << array[i] << ", ";
- }
- else {
- cout << "-" << array[i] << ", ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement