class Program { static void Main() { Console.WriteLine("Enter a number: "); int num = Convert.ToInt32(Console.ReadLine()); if (IsPrime(num)) { Console.WriteLine("Prime Number"); } else { Console.WriteLine("Not a Prime Number"); } } static Boolean IsPrime(int num) { if (num == 1 || num == 0) return false; int c = 0; for(int i = 1; i <= num; i++) { if(num%i == 0) { c++; } } return c == 2; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter