C++ GNU. Простое заполнение массива, а потом в цикле проверки.
В конце выводим результаты.
#include <iostream>
using namespace std;
int main()
{
const int size = 20;
int arr[size];
for (int i = 0; i < size; ++i)
cout << "Enter " << i << " element -> ";
cin >> arr[i];
}
int AllSum = 0;
int EvSum = 0;
int OddSum = 0;
int EvCounter = 0;
int OddCounter = 0;
int SmallThenZero = 0;
AllSum += arr[i];
if (arr[i] < 0) SmallThenZero++;
if (arr[i] % 2 == 0)
EvCounter++;
EvSum += arr[i];
else
OddCounter++;
OddSum += arr[i];
cout << "Even numbers counter - " << EvCounter << endl;
cout << "Odd numbers counter - " << OddCounter << endl;
cout << "Even numbers sum - " << EvSum << endl;
cout << "Odd numbers sum - " << OddSum << endl;
cout << "All numbers sum - " << AllSum << endl;
cout << "Small then zero numbers - " << SmallThenZero << endl;
cin.get();
C++ GNU. Простое заполнение массива, а потом в цикле проверки.
В конце выводим результаты.
Мой вариант решения:#include <iostream>
using namespace std;
int main()
{
const int size = 20;
int arr[size];
for (int i = 0; i < size; ++i)
{
cout << "Enter " << i << " element -> ";
cin >> arr[i];
}
int AllSum = 0;
int EvSum = 0;
int OddSum = 0;
int EvCounter = 0;
int OddCounter = 0;
int SmallThenZero = 0;
for (int i = 0; i < size; ++i)
{
AllSum += arr[i];
if (arr[i] < 0) SmallThenZero++;
if (arr[i] % 2 == 0)
{
EvCounter++;
EvSum += arr[i];
}
else
{
OddCounter++;
OddSum += arr[i];
}
}
cout << "Even numbers counter - " << EvCounter << endl;
cout << "Odd numbers counter - " << OddCounter << endl;
cout << "Even numbers sum - " << EvSum << endl;
cout << "Odd numbers sum - " << OddSum << endl;
cout << "All numbers sum - " << AllSum << endl;
cout << "Small then zero numbers - " << SmallThenZero << endl;
cin.get();
cin.get();
}