Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class PrimeNumCheck
- {
- static void Main()
- {
- uint intToCheck;
- int count = 0;
- Console.WriteLine("Provide a positive integer <= 100 to check:");
- while (!(uint.TryParse(Console.ReadLine(), out intToCheck) && (intToCheck <= 100)))
- {
- Console.WriteLine("Please, enter valid integer.");
- }
- if (intToCheck != 1)
- {
- for (int i = 2; i <= Math.Sqrt(intToCheck); i++)
- {
- count = count + (((intToCheck % i) == 0) ? 1 : 0);
- }
- }
- else
- {
- count = 2;
- }
- Console.WriteLine((count > 0) ? "Is Not Prime" : "Is Prime");
- Console.WriteLine("\nPress any key to exit");
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement