Advertisement
Alexander_B

Divide without remainder

Feb 17th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 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 DomashnoDevideWithhoutRemainder
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. // count numbers
  16.  
  17. int p1 = 0; // /2
  18. int p2 = 0; // /3
  19. int p3 = 0; // /4
  20.  
  21.  
  22. for (int i = 0; i < n; i++)
  23. {
  24. int input = int.Parse(Console.ReadLine());
  25.  
  26. if (input % 2 == 0)
  27. {
  28. p1++;
  29. }
  30.  
  31. if (input % 3 == 0)
  32. {
  33. p2++;
  34. }
  35.  
  36. if (input % 4 == 0)
  37. {
  38. p3++;
  39. }
  40. }
  41.  
  42. // calculate percentage
  43.  
  44. double p1Percent = 0.0;
  45. double p2Percent = 0.0;
  46. double p3Percent = 0.0;
  47.  
  48. if (p1 > 0)
  49. {
  50. p1Percent = 1.00 * p1 / n * 100;
  51. }
  52.  
  53. if (p2 > 0)
  54. {
  55. p2Percent = 1.00 * p2 / n * 100;
  56. }
  57.  
  58. if (p3 > 0)
  59. {
  60. p3Percent = 1.00 * p3 / n * 100;
  61. }
  62.  
  63.  
  64.  
  65. // print
  66.  
  67. Console.WriteLine($"{p1Percent:f2}%");
  68. Console.WriteLine($"{p2Percent:f2}%");
  69. Console.WriteLine($"{p3Percent:f2}%");
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement