Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class PrimeTest
- {
- //Write an expression that checks if given positive integer number
- //n (n ≤ 100) is prime. E.g. 37 is prime.
- static void Main()
- {
- Console.WriteLine("Enter a whole number to test for primality:");
- int userValue = int.Parse(Console.ReadLine());
- if (userValue == 2 || userValue == 3 || userValue == 5 || userValue == 7)
- {
- Console.WriteLine("This is a prime number!");
- }
- else if ((userValue % 2 != 0) && (userValue % 3 != 0) && (userValue % 5 != 0) && (userValue % 7 != 0))
- {
- Console.WriteLine("This is a prime number!");
- }
- else
- {
- Console.WriteLine("This is not a prime number.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement