Answer to Question #284708 in C++ for papi

Question #284708

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.


1
Expert's answer
2022-01-05T14:59:09-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog