SHARE
TWEET

PrimeTest

a guest Nov 6th, 2013 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3.     class PrimeTest
  4.     {
  5.         //Write an expression that checks if given positive integer number
  6.         //n (n ≤ 100) is prime. E.g. 37 is prime.
  7.  
  8.         static void Main()
  9.         {
  10.             Console.WriteLine("Enter a whole number to test for primality:");
  11.             int userValue = int.Parse(Console.ReadLine());
  12.  
  13.             if (userValue == 2 || userValue == 3 || userValue == 5 || userValue == 7)
  14.             {
  15.                 Console.WriteLine("This is a prime number!");
  16.             }
  17.             else if ((userValue % 2 != 0) && (userValue % 3 != 0) && (userValue % 5 != 0) && (userValue % 7 != 0))
  18.             {
  19.                 Console.WriteLine("This is a prime number!");
  20.             }
  21.             else
  22.             {
  23.                 Console.WriteLine("This is not a prime number.");
  24.             }
  25.         }
  26.     }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top