Advertisement
Masovski

[C# Basics][Loops-HW] 3. Min, Max, Sum and Average

Mar 29th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2.  
  3. class MinMaxSumAndAvarageOfN
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.  
  9.         int max = int.MinValue;
  10.         int min = int.MaxValue;
  11.         double sum = 0;
  12.         double avg = 0;
  13.        
  14.         for (int i = 0; i < n; i++)
  15.         {
  16.             int x = int.Parse(Console.ReadLine());
  17.             if (x > max)
  18.             {
  19.                 max = x;
  20.             }
  21.             if (x < min)
  22.             {
  23.                 min = x;
  24.             }
  25.             sum += x;
  26.  
  27.         }
  28.         avg = sum / n;
  29.  
  30.         Console.WriteLine("Min is {0}", min);
  31.         Console.WriteLine("Max is {0}", max);
  32.         Console.WriteLine("Sum is {0}", sum);
  33.         Console.WriteLine("Avg is {0:0.00}", avg);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement