Approach
Console.WriteLine( $" {inputNumber} / {i} = { inputNumber / i} (remainder: {inputNumber % i})" );
Console.Write( "Enter a Positive Number: " );
int inputNumber = Convert.ToInt32( Console.ReadLine() );
int counter = 0;
for ( int i = 1; i <= inputNumber; i++ ) {
if ( inputNumber == 0 || inputNumber == 1 || counter > 2 ) { break; }
if ( inputNumber % i == 0 ) { counter++; }
}
if ( counter == 2 ) {
Console.WriteLine( $"{inputNumber} is a prime number." );
} else if ( inputNumber == 1 || inputNumber == 0 ) {
Console.WriteLine( $"{inputNumber} is neither prime nor composite." );
} else {
Console.WriteLine( $"{inputNumber} is not a prime number. (It is a composite number)" );
}
My reference: https://www.tutorialspoint.com/Chash-Program-to-check-if-a-number-is-prime-or-not