Advertisement
VyaraG

PrimeNumberChecker

Nov 28th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System;
  2.  
  3. ////Write an expression that checks if given positive integer number n (n ≤ 100) is prime (i.e. it is divisible without remainder only to itself and 1).
  4.  
  5.  
  6. class PrimeNumebrCheck
  7. {
  8.     static void Main()
  9.     {
  10.         Console.Write("Enter a positive number, smaller or equal to 100: ");
  11.         int n = int.Parse(Console.ReadLine());
  12.         bool isPrime = false;
  13.  
  14.         if ((n>1) && (n<=100))
  15.         {
  16.           for (int i = 2; i <=n; i++)
  17.         {
  18.             if (n%i==0)
  19.             {
  20.                 isPrime = true;
  21.             }
  22.            
  23.         }
  24.         Console.WriteLine(isPrime);  
  25.         }
  26.         else
  27.         {
  28.             Console.WriteLine("False");
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement