Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*Problem 3. Min, Max, Sum and Average of N Numbers
- Write a program that reads from the console a sequence of n integer numbers and returns the minimal, the maximal number,
- the sum and the average of all numbers (displayed with 2 digits after the decimal point).
- The input starts by the number n (alone in a line) followed by n lines, each holding an integer number.
- The output is like in the examples below.
- input output
- 2 min = 1
- 5 max = 5
- 1 sum = 8
- avg = 2.67*/
- class MinMaxSumAverage
- {
- static void Main()
- {
- Console.Write("How many numbers are you going to enter? ");
- int number = int.Parse(Console.ReadLine());
- int min = int.MaxValue;
- int max = int.MinValue;
- int sum = 0;
- for (int i = 0; i < number; i++)
- {
- int n = int.Parse(Console.ReadLine());
- if (max < n) max = n;
- if (min > n) min = n;
- sum += n;
- }
- double avergage = sum / number;
- Console.WriteLine("Sum: " + sum);
- Console.WriteLine("Min: " + min);
- Console.WriteLine("Max: " + max);
- Console.WriteLine("Avg: " + avergage);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement