Advertisement
alexbancheva

Histogramme

Nov 16th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Histogramme
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int n = int.Parse(Console.ReadLine());
  10.  
  11. double p1 = 0;
  12. double p2 = 0;
  13. double p3 = 0;
  14. double p4 = 0;
  15. double p5 = 0;
  16.  
  17.  
  18.  
  19. for (int i = 1; i <= n; i++)
  20. {
  21. int currentNumber = int.Parse(Console.ReadLine());
  22.  
  23. if (currentNumber < 200)
  24. {
  25. p1++;
  26. }
  27. else if ((currentNumber >= 200) && (currentNumber <= 399))
  28. {
  29. p2++;
  30. }
  31. else if ((currentNumber >= 400) && (currentNumber <= 599))
  32. {
  33. p3++;
  34. }
  35. else if ((currentNumber >= 600) && (currentNumber <= 799))
  36. {
  37. p4++;
  38. }
  39. else if (currentNumber >= 800)
  40. {
  41. p5++;
  42. }
  43.  
  44. }
  45.  
  46. double pInRange1 = (p1 / n) * 100;
  47. double pInRange2 = (p2 / n) * 100;
  48. double pInRange3 = (p3 / n) * 100;
  49. double pInRange4 = (p4 / n) * 100;
  50. double pInRange5 = (p5 / n) * 100;
  51.  
  52. Console.WriteLine($"{pInRange1:f2}%");
  53. Console.WriteLine($"{pInRange2:f2}%");
  54. Console.WriteLine($"{pInRange3:f2}%");
  55. Console.WriteLine($"{pInRange4:f2}%");
  56. Console.WriteLine($"{pInRange5:f2}%");
  57.  
  58.  
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement