Advertisement
braveheart1989

Problem3.Min, Max, Sum and Average of N Number

Feb 4th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03.Min_Max_Sum_And_Average_Of_N_Numbers
  8. {
  9.     class Min_Max_Sum_And_Average
  10.     {
  11.         static void Main()
  12.         {
  13.             //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.
  14.  
  15.             //3     min = 1
  16.             //2     max = 5
  17.             //5     sum = 8
  18.             //1     avg = 2.67
  19.        
  20.        
  21.    
  22.  
  23.  
  24.             int number = int.Parse(Console.ReadLine());
  25.             int minimal = 0;
  26.             int maximal = 0;
  27.             double sum = 0;
  28.             double average = 0;
  29.             int count = 0;
  30.  
  31.             while (count < number)
  32.             {
  33.                 count++;
  34.  
  35.                 int n1 = int.Parse(Console.ReadLine());
  36.                 sum += n1;
  37.                 average = sum / number;
  38.             }
  39.  
  40.             Console.WriteLine();
  41.  
  42.             Console.WriteLine("min={0}", minimal);
  43.             Console.WriteLine("max={0}", maximal);
  44.             Console.WriteLine("sum={0}", sum);
  45.             Console.WriteLine("avg={0:F2}", average);
  46.         }
  47.     }    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement