Advertisement
Valantina

Hisogram2

May 26th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Hisogram2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             // p1 са под 200, друг процент p2 са от 200 до 399, друг процент p3 са от 400 до 599, друг процент p4 са от 600 до 799 и останалите p5 процента са от 800 нагоре.
  12.             // Да се напише програма, която изчислява и отпечатва процентите p1, p2, p3, p4 и p5.
  13.  
  14.             int countP1 = 0;
  15.             int countP2 = 0;
  16.             int countP3 = 0;
  17.             int countP4 = 0;
  18.             int countP5 = 0;
  19.             int countAll = 0;
  20.  
  21.  
  22.             for (int count = 1; count <= n; count++)
  23.             {
  24.                 int number = int.Parse(Console.ReadLine());
  25.  
  26.                 if (number < 200)
  27.                 {
  28.                     countP1++;
  29.                 }
  30.                 else if (number >= 200 && number <= 399)
  31.                 {
  32.                     countP2++;
  33.                 }
  34.                 else if (number >= 400 && number <= 599)
  35.                 {
  36.                     countP3++;
  37.                 }
  38.                 else if (number >= 600 && number <= 799)
  39.                 {
  40.                     countP4++;
  41.                 }
  42.                 else if (number >= 800)
  43.                 {
  44.                     countP5++;
  45.                 }
  46.             }
  47.  
  48.             countAll = countP1 + countP2 + countP3 + countP4 + countP5;
  49.  
  50.             double percentageP1 = countP1 * 1.0 / countAll * 100;
  51.             double percentageP2 = countP2 * 1.0 / countAll * 100;
  52.             double percentageP3 = countP3 * 1.0 / countAll * 100;
  53.             double percentageP4 = countP4 * 1.0 / countAll * 100;
  54.             double percentageP5 = countP5 * 1.0 / countAll * 100;
  55.  
  56.  
  57.             Console.WriteLine($"{percentageP1:F2}%");
  58.             Console.WriteLine($"{percentageP2:F2}%");
  59.             Console.WriteLine($"{percentageP3:F2}%");
  60.             Console.WriteLine($"{percentageP4:F2}%");
  61.             Console.WriteLine($"{percentageP5:F2}%");
  62.  
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement