ralichka

5.4.While.Loop-AverageNumber

Jul 4th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using System;
  2.  
  3. namespace AverageNumber
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int num = int.Parse(Console.ReadLine());
  10.  
  11.             int counter = 0;
  12.             double numSum = 0;
  13.  
  14.             while (counter < num)
  15.             {
  16.                 double number=double.Parse(Console.ReadLine());
  17.                 counter++;
  18.                 numSum += number;
  19.  
  20.             }
  21.             if (counter >= num)
  22.             {
  23.                 double average = numSum / num;
  24.                 Console.WriteLine($"{average:f2}");
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment