Created
August 13, 2015 09:45
-
-
Save vdonchev/baca2338a6ca43256954 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class SomePrimes | |
{ | |
static void Main() | |
{ | |
Console.WriteLine("Enter a number to check if it's prime:"); | |
int prime = int.Parse(Console.ReadLine()); | |
if (prime <= 1) | |
{ | |
Console.WriteLine("Your number is NOT prime."); | |
} | |
else if (prime == 2) | |
{ | |
Console.WriteLine("Your number is prime."); | |
} | |
else if (prime % 2 == 0) | |
{ | |
Console.WriteLine("Your number is NOT prime."); | |
} | |
else | |
{ | |
bool isPrime = true; | |
for (int i = 2; i <= prime - 1; i++) | |
{ | |
if (prime % i == 0) | |
{ | |
isPrime = false; | |
} | |
} | |
if (isPrime) | |
{ | |
Console.WriteLine("Your number is prime."); | |
} | |
else | |
{ | |
Console.WriteLine("Your number is NOT prime."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment