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).
- using System;
- class PrimeNum
- {
- static void Main()
- {
- Console.Write("Enter number: ");
- string numA = Console.ReadLine();
- int newNumA = int.Parse(numA);
- while (newNumA <= 0)
- {
- Console.WriteLine("Number is not positive.");
- Console.Write("Enter number: ");
- newNumA = int.Parse(Console.ReadLine());
- }
- if ((newNumA == 2) || (newNumA == 3) || (newNumA == 5))
- {
- Console.WriteLine("true");
- }
- else if (((newNumA % 2 == 0) || (newNumA % 3 == 0) || (newNumA % 5 == 0)) || (newNumA == 1))
- {
- Console.WriteLine("false");
- }
- else
- {
- Console.WriteLine("true");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement