Advertisement
VladoG

19-Histogram-exam2016-03-06

Mar 18th, 2016
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 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 _19_Histogram_exam2016_03_06
  8.     {
  9.     class Histogram
  10.         {
  11.         static void Main(string[] args)
  12.             {
  13.             double p1 = 0.0;
  14.             double p2 = 0.0;
  15.             double p3 = 0.0;
  16.             double p4 = 0.0;
  17.             double p5 = 0.0;
  18.             int num;
  19.             var n = int.Parse(Console.ReadLine());
  20.  
  21.             for (int i = 0; i < n; i++)
  22.                 {
  23.                 num = int.Parse(Console.ReadLine());
  24.  
  25.                 if (num<200)
  26.                     {
  27.                     p1 += 1;
  28.                     }
  29.                 else
  30.                     {
  31.                     if (num>=200&&num<400)
  32.                         {
  33.                         p2 += 1;
  34.                         }
  35.                     else
  36.                         {
  37.                         if (num>=400&&num<600)
  38.                             {
  39.                             p3 += 1;
  40.                             }
  41.                         else
  42.                             {
  43.                             if (num>=600&&num<800)
  44.                                 {
  45.                                 p4 += 1;
  46.                                 }
  47.                             else
  48.                                 {
  49.                                 if (num>=800)
  50.                                     {
  51.                                     p5 += 1;
  52.                                     }
  53.                                 }
  54.                             }
  55.                         }
  56.                     }
  57.                 }
  58.             p1 = (p1 / n) * 100;
  59.             Console.WriteLine("{0:f2}%",p1);
  60.             p2 = (p2 / n) * 100;
  61.             Console.WriteLine("{0:f2}%", p2);
  62.             p3 = (p3 / n) * 100;
  63.             Console.WriteLine("{0:f2}%", p3);
  64.             p4 = (p4 / n) * 100;
  65.             Console.WriteLine("{0:f2}%", p4);
  66.             p5 = (p5 / n) * 100;
  67.             Console.WriteLine("{0:f2}%", p5);
  68.  
  69.             }
  70.         }
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement