SHARE
TWEET

IfNumberIsPrime

SasnycoN Jan 11th, 2014 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace IfNumberIsPrime
  8. {
  9.     class IfNumberIsPrime
  10.     {
  11.         static void Main()
  12.         {
  13.             Console.WriteLine("We will check if a number from 2 to 100 is prime!"); //CONDITION
  14.             Console.Write("Write a number: ");
  15.             int numberToCheck = int.Parse(Console.ReadLine());
  16.  
  17.             int checkTwo = 2;
  18.             int checkThree = 3;
  19.             int checkFive = 5;
  20.             int checkSeven = 7;
  21.  
  22.             if (numberToCheck == 1) //checking if the number satisfy the condition
  23.                 {
  24.                     Console.WriteLine("WRONG NUMBER!!!");
  25.                 }
  26.             else if (numberToCheck  > 100) ///checking if the number satisfy the condition
  27.                 {
  28.                     Console.WriteLine("WRONG NUMBER!!!");
  29.                 }
  30.             else if (numberToCheck < 1) //checking if the number satisfy the condition
  31.                 {
  32.                     Console.WriteLine("WRONG NUMBER!!!");
  33.                 }
  34.             else if (numberToCheck == 2) //Checking if the number is 2
  35.                 {
  36.                     Console.WriteLine("The number IS prime!");
  37.                 }
  38.             else if ((numberToCheck % checkTwo) == 0)
  39.                 {
  40.                     Console.WriteLine("The number IS NOT prime!");
  41.                 }
  42.             else if ((numberToCheck % checkThree) == 0)
  43.                 {
  44.                     Console.WriteLine("The number IS NOT prime!");          
  45.                 }
  46.             else if ((numberToCheck % checkFive) == 0)
  47.                 {
  48.                     Console.WriteLine("The number IS NOT prime!");
  49.                 }
  50.             else if ((numberToCheck % checkSeven) == 0)
  51.                 {
  52.                     Console.WriteLine("The number IS NOT prime!");
  53.                 }
  54.             else
  55.                 {
  56.                     Console.WriteLine("The number IS prime!");
  57.                 }
  58.         }
  59.     }
  60. }
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