Input N integers(Ask from the user how many nos. he/she wants to input). Determine and
print the sum of all nos., the average of all numbers, how many odd nos. were inputted,
how many even nos. were entered and how many zeroes inputted.
#include<iostream>
using namespace std;
int main()
{
int N;
cout << "How many numbers do you want to enter?\n";
cout << "Your choice: ";
cin >> N;
int* arr = new int[N];
cout << "Enter numbers: ";
for (int i = 0; i < N; i++)
{
cin >> arr[i];
}
double summ=0;
int odd = 0;
int even = 0;
int zeroes = 0;
cout << "Summ of all numbers is ";
for (int i = 0; i < N; i++)
{
summ += arr[i];
if (arr[i] % 2 == 0)
even++;
if (arr[i] % 2 == 1)
odd++;
if (arr[i]==0)
zeroes++;
}
cout << summ;
cout << "\nThe average of all numbers is "
<< (double)summ / N;
cout << "\nNumber of even is " << even;
cout << "\nNumber of odd is " << odd;
cout << "\nNumber of zeroes is " << zeroes;
delete[] arr;
}
Comments
Leave a comment