Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _03.Min_Max_Sum_And_Average_Of_N_Numbers
- {
- class Min_Max_Sum_And_Average
- {
- static void Main()
- {
- //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.
- //3 min = 1
- //2 max = 5
- //5 sum = 8
- //1 avg = 2.67
- int number = int.Parse(Console.ReadLine());
- int minimal = 0;
- int maximal = 0;
- double sum = 0;
- double average = 0;
- int count = 0;
- while (count < number)
- {
- count++;
- int n1 = int.Parse(Console.ReadLine());
- sum += n1;
- average = sum / number;
- }
- Console.WriteLine();
- Console.WriteLine("min={0}", minimal);
- Console.WriteLine("max={0}", maximal);
- Console.WriteLine("sum={0}", sum);
- Console.WriteLine("avg={0:F2}", average);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement