fbinnzhivko

04. Histogram

Mar 15th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main(string[] args)
  5.     {
  6.         int n = int.Parse(Console.ReadLine());
  7.  
  8.         int p1 = 0;
  9.         int p2 = 0;
  10.         int p3 = 0;
  11.         int p4 = 0;
  12.         int p5 = 0;
  13.  
  14.         for (int i = 0; i < n; i++)
  15.         {
  16.             var num = int.Parse(Console.ReadLine());
  17.                  if (num < 200) { p1++; }
  18.             else if (num < 400) { p2++; }
  19.             else if (num < 600) { p3++; }
  20.             else if (num < 800) { p4++; }
  21.             else if (num <= 1000) { p5++; }
  22.         }
  23.         var p1Percentage = p1 * 100d / n;
  24.         var p2Percentage = p2 * 100d / n;
  25.         var p3Percentage = p3 * 100d / n;
  26.         var p4Percentage = p4 * 100d / n;
  27.         var p5Percentage = p5 * 100d / n;
  28.  
  29.  
  30.         Console.WriteLine("{0:f2}%", p1Percentage);
  31.         Console.WriteLine("{0:f2}%", p2Percentage);
  32.         Console.WriteLine("{0:f2}%", p3Percentage);
  33.         Console.WriteLine("{0:f2}%", p4 * 100d / n);
  34.         Console.WriteLine("{0:f2}%", p5 * 100d / n);
  35.     }
  36. }
Add Comment
Please, Sign In to add comment