Advertisement
pupesko

SoftUni - 5.8 Prime Number Check

Oct 11th, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. //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).
  2.  
  3. using System;
  4.  
  5. class PrimeNum
  6. {
  7.     static void Main()
  8.     {
  9.         Console.Write("Enter number: ");
  10.         string numA = Console.ReadLine();
  11.         int newNumA = int.Parse(numA);
  12.  
  13.         while (newNumA <= 0)
  14.         {
  15.             Console.WriteLine("Number is not positive.");
  16.             Console.Write("Enter number: ");
  17.             newNumA = int.Parse(Console.ReadLine());
  18.         }
  19.  
  20.         if ((newNumA == 2) || (newNumA == 3) || (newNumA == 5))
  21.         {
  22.             Console.WriteLine("true");
  23.         }
  24.         else if (((newNumA % 2 == 0) || (newNumA % 3 == 0) || (newNumA % 5 == 0)) || (newNumA == 1))
  25.         {
  26.             Console.WriteLine("false");
  27.         }
  28.         else
  29.         {
  30.             Console.WriteLine("true");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement