input N integers (ask from the user how many numbers he/she wants to input) determine and print the sum of all numbers, the average of all numbers, how many odd numbers were inputted, how many even numbers were entered and how many zeroes inputted
1
Expert's answer
2012-10-22T07:41:03-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int n = 0;
Console.WriteLine("Input N: "); n = int.Parse(Console.ReadLine()); int[] num = new int[n]; int sum = 0; int even = 0;
int odd = 0; int zeroes = 0; for (int i = 0; i < n; i++) { Console.WriteLine("Input new integer: "); num[i] = int.Parse(Console.ReadLine()); sum = sum + num[i]; if (num[i] % 2 == 0)
{ even++; }
else { odd++;
} if (num[i] == 0)
{ zeroes++; }
} int ave = sum / n; Console.WriteLine("Sum: " + sum); Console.WriteLine("Average: " + ave);
Comments
Leave a comment