SHARE
TWEET

Is it prime

a guest Nov 8th, 2013 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3.     class PrimeNr
  4.     {
  5.         static void Main()
  6.         {
  7.             Console.Write("Enter a number from 2 to 100: ");
  8.             int input;
  9.             int remain=1;
  10.             while ((!int.TryParse(Console.ReadLine(), out input)) || !(input <= 100 && input > 1))
  11.             {
  12.                 Console.WriteLine("\nPlease enter a number from 2 to 100: ");
  13.             }
  14.             for (int i = 2; i < input; i++)
  15.             {
  16.                 remain = input % i;
  17.                 if (remain == 0)
  18.                 {
  19.                     Console.WriteLine("\n{0} is composite number.\n",input);
  20.                     break;
  21.                 }
  22.             }
  23.             if (remain != 0)
  24.             {
  25.                 Console.WriteLine("\n{0} is prime number.\n",input);
  26.             }
  27.         }
  28.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top