Advertisement
Guest User

Untitled

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