Консультация № 195693
22.05.2019, 13:13
0.00 руб.
1 2 1
Здравствуйте! Прошу помощи в следующем вопросе:
Задание необходимо выполнить в Microsoft Visual C++ 2010,экспресс-выпуск,Windows(любая,но желательно 8 или 10)

Прикрепленные файлы:
1bc96ad2508ba9befbf65094bbc90e1ea75d4e46.png

Обсуждение

давно
Посетитель
403031
5
22.05.2019, 13:27
общий
Никаких отчетов оформлять не нужно,только написать программу.
давно
Советник
400484
472
22.05.2019, 14:04
общий
это ответ
Здравствуйте, Apricot!
Вот примерный код:
Код:

#include <iostream>

using namespace std;

int main()
{
cout << "Input the number of real numeric: ";
int num = 0;
// перехват исключения, если введено не число
cin.exceptions(istream::failbit | istream::badbit);
try
{
cin >> num;
}
catch (...)
{
cout << "Input is not a real number" << endl;
return -1;
}

int input, compare;
bool inputFirst = true; // первый ввод
short moreFirst = 0; // количество чисел больше первого
while (num-- > 0)
{
cout << "Input real numeric: ";
try
{
cin >> input;
}
catch (...)
{
cout << "Input is not a real number" << endl;
return -1;
}

if (inputFirst)
{
compare = input;
inputFirst = false;
}
else
{
if (abs(compare) < abs(input))
{
moreFirst++;
}
}
}

cout << "The number of elements is greater than the first modulo: " << moreFirst << endl;

return 0;
}

вывод в консоле:
Код:

Input the number of real numeric: 3
Input real numeric: 2
Input real numeric: -1
Input real numeric: 3
The number of elements is greater than the first modulo: 1
5
Форма ответа