I am trying to find the next prime number after the number the user enters in.
Here is the code I have so far:
public int Calculation(int number)
{
//set the isPrime to false
bool isPrime = false;
//do this while isPrime is still false
do
{
//increment the number by 1 each time
number = number + 1;
int squaredNumber = (int)Math.Sqrt(number);
//start at 2 and increment by 1 until it gets to the squared number
for (int i = 2; i <= squaredNumber; i++)
{
//how do I check all i's?
if (number % i != 0)
{
isPrime = true;
}
}
} while (isPrime == false);
//return the prime number
return number;
}
I know something is missing because the first time i gives a remainder that is NOT 0 then it returns that number as prime. The problem is I can't figure out the logic/syntax to see if every i in that loop is NOT 0 as remainder.