YavorJS

Histogram

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