Advertisement
desislava_topuzakova

05. Division Without Remainder

Jul 18th, 2020
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02._Odd_Occurrences
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             int n = int.Parse(Console.ReadLine());
  11.             int countFirst = 0; //броя на числата в група 1
  12.             int countSecond = 0; //броя на числата в група 2
  13.             int countThird = 0; //броя на числата в група 3
  14.  
  15.             for (int number = 1; number <= n; number++)
  16.             {
  17.                 int value = int.Parse(Console.ReadLine());
  18.  
  19.                 //проверка за група 1
  20.                 if (value % 2 == 0)
  21.                 {
  22.                     countFirst++;
  23.                 }
  24.                 //проверка за група 2
  25.                 if (value % 3 == 0)
  26.                 {
  27.                     countSecond++;
  28.                 }
  29.                 //проверка за група 3
  30.                 if (value % 4 == 0)
  31.                 {
  32.                     countThird++;
  33.                 }
  34.             }
  35.  
  36.             //броят на числата във всяка група
  37.  
  38.             //процент = бр. / общ брой числа * 100
  39.             double percentFirst = countFirst * 1.0 / n * 100;
  40.             double percentSecond = countSecond * 1.0 / n * 100;
  41.             double percentThird = countThird * 1.0 / n * 100;
  42.  
  43.             Console.WriteLine($"{percentFirst:F2}%");
  44.             Console.WriteLine($"{percentSecond:F2}%");
  45.             Console.WriteLine($"{percentThird:F2}%");
  46.  
  47.  
  48.  
  49.  
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement