Guest User

Histogram

a guest
Nov 10th, 2017
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Results
  4. {
  5.     public class Histogram
  6.     {
  7.         public static void Main()
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             int p1 = 0;
  12.             int p2 = 0;
  13.             int p3 = 0;
  14.             int p4 = 0;
  15.             int p5 = 0;
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 var num = int.Parse(Console.ReadLine());
  20.                 if (num < 200)
  21.                 {
  22.                     p1++;
  23.                 }
  24.                 else if (num >= 200 && num <= 399)
  25.                 {
  26.                     p2++;
  27.                 }
  28.                 else if (num >= 400 && num <= 599)
  29.                 {
  30.                     p3++;
  31.                 }
  32.                 else if (num >= 600 && num <= 799)
  33.                 {
  34.                     p4++;
  35.                 }
  36.                 else if (num >= 800)
  37.                 {
  38.                     p5++;
  39.                 }
  40.             }
  41.             double p1Percentage = p1 * 100d / n;
  42.             double p2Percentage = p2 * 100d / n;
  43.             double p3Percentage = p3 * 100d / n;
  44.             double p4Percentage = p4 * 100d / n;
  45.             double p5Percentage = p5 * 100d / n;
  46.  
  47.  
  48.             Console.WriteLine("{0:f2}%", p1Percentage);
  49.             Console.WriteLine("{0:f2}%", p2Percentage);
  50.             Console.WriteLine("{0:f2}%", p3Percentage);
  51.             Console.WriteLine("{0:f2}%", p4Percentage);
  52.             Console.WriteLine("{0:f2}%", p5Percentage);
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment