Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write an expression that checks if given positive integer number n (n ≤ 100) is prime (i.e. it is divisible without remainder only to itself and 1).
- namespace _08.PrimeNumberCheck
- {
- using System;
- public class PrimeNumberCheck
- {
- public static void Main(string[] args)
- {
- checked
- {
- Console.Write("Enter a whole number, [num <= 100]: ");
- int num = int.Parse(Console.ReadLine());
- bool numIsPrime = false;
- num = Math.Abs(num);
- if ((num == 2 || num == 3 || num == 5 || num == 7) ||
- num != 1 && num % 2 != 0 && num % 3 != 0 && num % 5 != 0 && num % 7 != 0)
- {
- numIsPrime = true;
- }
- Console.WriteLine("Given number Is Prime: {0} !", numIsPrime);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement