Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Hisogram2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- // p1 са под 200, друг процент p2 са от 200 до 399, друг процент p3 са от 400 до 599, друг процент p4 са от 600 до 799 и останалите p5 процента са от 800 нагоре.
- // Да се напише програма, която изчислява и отпечатва процентите p1, p2, p3, p4 и p5.
- int countP1 = 0;
- int countP2 = 0;
- int countP3 = 0;
- int countP4 = 0;
- int countP5 = 0;
- int countAll = 0;
- for (int count = 1; count <= n; count++)
- {
- int number = int.Parse(Console.ReadLine());
- if (number < 200)
- {
- countP1++;
- }
- else if (number >= 200 && number <= 399)
- {
- countP2++;
- }
- else if (number >= 400 && number <= 599)
- {
- countP3++;
- }
- else if (number >= 600 && number <= 799)
- {
- countP4++;
- }
- else if (number >= 800)
- {
- countP5++;
- }
- }
- countAll = countP1 + countP2 + countP3 + countP4 + countP5;
- double percentageP1 = countP1 * 1.0 / countAll * 100;
- double percentageP2 = countP2 * 1.0 / countAll * 100;
- double percentageP3 = countP3 * 1.0 / countAll * 100;
- double percentageP4 = countP4 * 1.0 / countAll * 100;
- double percentageP5 = countP5 * 1.0 / countAll * 100;
- Console.WriteLine($"{percentageP1:F2}%");
- Console.WriteLine($"{percentageP2:F2}%");
- Console.WriteLine($"{percentageP3:F2}%");
- Console.WriteLine($"{percentageP4:F2}%");
- Console.WriteLine($"{percentageP5:F2}%");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement