Advertisement
kuruku

MinMaxSumAverageNumbers

May 3rd, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2.  
  3. //Write a program that reads from the console a sequence of n integer numbers and
  4. //returns the minimal, the maximal number, the sum and the average of all numbers
  5. //(displayed with 2 digits after the decimal point). The input starts by the number
  6. //n (alone in a line) followed by n lines, each holding an integer number.
  7. //The output is like in the examples below
  8.  
  9.     class MinMaxSumAverageNumbers
  10.     {
  11.         static void Main()
  12.         {
  13.             Console.Write("N = ");
  14.             int n = int.Parse(Console.ReadLine());
  15.             int min = int.MaxValue;
  16.             int max = int.MinValue;
  17.             int sum = 0;
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 int nums = int.Parse(Console.ReadLine());
  21.                 if (nums < min)
  22.                 {
  23.                     min = nums;
  24.                 }
  25.                 else if (nums > max)
  26.                 {
  27.                     max = nums;
  28.                 }
  29.                 sum += nums;
  30.             }
  31.             Console.WriteLine("min = {0}",min);
  32.             Console.WriteLine("max = {0}", max);
  33.             Console.WriteLine("sum = {0}", sum);
  34.             double avg = (double)sum / n;
  35.             Console.WriteLine("avg = {0:F2}", avg);
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement