Advertisement
IvetValcheva

03. Histogram

Jan 31st, 2022
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp37
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             double p1 = 0;
  16.             double p2 = 0;
  17.             double p3 = 0;
  18.             double p4 = 0;
  19.             double p5 = 0;
  20.  
  21.             for (int i = 1; i <= n; i++)
  22.             {
  23.                 int num = int.Parse(Console.ReadLine());
  24.                 if (num<=199)
  25.                 {
  26.                     p1=p1+1;
  27.                 }
  28.                 else if (num<=399)
  29.                 {
  30.                     p2 = p2 + 1;
  31.                 }
  32.                 else if (num<=599)
  33.                 {
  34.                     p3 = p3 + 1;
  35.                 }
  36.                 else if (num <=799)
  37.                 {
  38.                     p4 = p4 + 1;
  39.  
  40.                 }
  41.                 else
  42.                 {
  43.                     p5 = p5 + 1;    
  44.                 }
  45.             }
  46.             p1 = p1 / n * 100;
  47.             p2 = p2 / n * 100;
  48.             p3 = p3 / n * 100;
  49.             p4 = p4 / n * 100;
  50.             p5 = p5 / n * 100;
  51.  
  52.             Console.WriteLine($"{p1:f2}%");
  53.             Console.WriteLine($"{p2:f2}%");
  54.             Console.WriteLine($"{p3:f2}%");
  55.             Console.WriteLine($"{p4:f2}%");
  56.             Console.WriteLine($"{p5:f2}%");
  57.  
  58.  
  59.         }
  60.     }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement