Advertisement
SMASIF

C# - Prime Or Not

Mar 10th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 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 PrimeNumberApp
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int num1;
  14.  
  15.             Console.WriteLine("Input number: ");
  16.             num1 = Convert.ToInt32(Console.ReadLine());
  17.             if (num1 == 0 || num1 == 1)
  18.             {
  19.                 Console.WriteLine(num1 + " is not prime number");
  20.                 Console.ReadLine();
  21.             }
  22.             else
  23.             {
  24.                 for (int a = 2; a <= num1 / 2; a++)
  25.                 {
  26.                     if (num1 % a == 0)
  27.                     {
  28.                         Console.WriteLine(num1 + " is not prime number");
  29.                         Console.ReadLine();
  30.                         return;
  31.                     }
  32.  
  33.                 }
  34.                 Console.WriteLine(num1 + " is a prime number");
  35.                 Console.ReadLine();
  36.             }
  37.             Console.ReadKey();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement