Greetings cblue,
> does anyone know hoew to find a prime sumber of a single number inputed by the ser using the following function and printing out if the number is prime
Yes, I do know, its quite possible too.
int main() {
int num;
cout << "enter number:";
cin >> num;
if (isPrime(num))
cout << "Number is prime" << endl;
else
cout << "Number is not prime" << endl;
return 0;
}
// Add isPrime code here How did this work? Simple, the if statement is used to express decisions. Formally the syntax is:
if (expression)
statement1
else
statement2
Where the else is optional. The expression is evaluated; if it is true (if has a non-zero value), statement1, is executed. If it is false, (if has value of zero) and if there is an else part, statement2 is executed instead.
Since an if simply tests the numeric value of an expression, certain coding shortcuts are possible:
Instead of:
If you have further questions, please feel free to ask. Hope this helps.
-
Stack
Overflow