IvetValcheva

04. Histogram

Apr 26th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace OnTimeForTheExam
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             double p1 = 0.00;
  12.             double p2 = 0.00;
  13.             double p3 = 0.00;
  14.             double p4 = 0.00;
  15.             double p5 = 0.00;
  16.  
  17.             for (int i = 1; i <= n; i++)
  18.             {
  19.                 int num = int.Parse(Console.ReadLine());
  20.  
  21.                 if (num < 200)
  22.                 {
  23.                     //p1 = p1 + 1;
  24.                     //p1+=1;
  25.                     p1++;
  26.                 }
  27.                 else if (num < 400)
  28.                 {
  29.                     p2++;
  30.                 }
  31.                 else if (num < 600)
  32.                 {
  33.                     p3++;
  34.                 }
  35.                 else if (num < 800)
  36.                 {
  37.                     p4++;
  38.                 }
  39.                 else
  40.                 {
  41.                     p5++;
  42.                 }
  43.             }
  44.  
  45.             p1 = p1 / n * 100;
  46.             p2 = p2 / n * 100;
  47.             p3 = p3 / n * 100;
  48.             p4 = p4 / n * 100;
  49.             p5 = p5 /n  * 100;
  50.  
  51.             Console.WriteLine($"{p1:F2}%");
  52.             Console.WriteLine($"{p2:F2}%");
  53.             Console.WriteLine($"{p3:F2}%");
  54.             Console.WriteLine($"{p4:F2}%");
  55.             Console.WriteLine($"{p5:F2}%");
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment