Advertisement
YankoZlatanov

PrimeNumberCheck

Nov 13th, 2014
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2.  
  3.     class PrimeNumberCheck
  4.     {
  5.         static void Main()
  6.         {
  7.             int input = int.Parse(Console.ReadLine());
  8.             int divider = 1;
  9.             bool answer = false;
  10.             int count = 0;
  11.             for (divider = 1; divider <= input; divider++)  // cicle run until it reaches the value of input number, because there is no sense to divide at larger number
  12.             {
  13.                 if (input % divider == 0)
  14.                 {
  15.                     count++;        // count how many times the number is divided without remainder
  16.                 }
  17.             }
  18.             if (count == 2)         // To be true , the input number must by divided without remainder only 2 times, with "1" and itself.
  19.             {                      
  20.                 answer = true;
  21.             }
  22.             Console.WriteLine(answer);
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement