Advertisement
tsvetelinapasheva

TsvetelinaPasheva/ForLoopExercise/04.Histogram

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