Advertisement
Dianov

For Loop - Exercise (05. Divide Without Remainder)

Dec 27th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 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 DivideWithoutRemainder
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             double counter1 = 0;
  15.             double counter2 = 0;
  16.             double counter3 = 0;
  17.  
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 int number = int.Parse(Console.ReadLine());
  21.                 if (number % 2 == 0)
  22.                 {
  23.                     counter1 += 1;
  24.                 }
  25.                 if (number % 3 == 0)
  26.                 {
  27.                     counter2 += 1;
  28.                 }
  29.                 if (number % 4 == 0)
  30.                 {
  31.                     counter3 += 1;
  32.                 }
  33.             }
  34.             double p1 = counter1 / n * 100;
  35.             double p2 = counter2 / n * 100;
  36.             double p3 = counter3 / n * 100;
  37.            
  38.             Console.WriteLine($"{p1:F2}%");
  39.             Console.WriteLine($"{p2:F2}%");
  40.             Console.WriteLine($"{p3:F2}%");
  41.         }  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement