Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //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
- class MinMaxSumAverageNumbers
- {
- static void Main()
- {
- Console.Write("N = ");
- int n = int.Parse(Console.ReadLine());
- int min = int.MaxValue;
- int max = int.MinValue;
- int sum = 0;
- for (int i = 0; i < n; i++)
- {
- int nums = int.Parse(Console.ReadLine());
- if (nums < min)
- {
- min = nums;
- }
- else if (nums > max)
- {
- max = nums;
- }
- sum += nums;
- }
- Console.WriteLine("min = {0}",min);
- Console.WriteLine("max = {0}", max);
- Console.WriteLine("sum = {0}", sum);
- double avg = (double)sum / n;
- Console.WriteLine("avg = {0:F2}", avg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement