Hey guys. Started C a couple weeks ago and I'm trying to learn how to implement functions. I need to make a function which returns a 1 if its a prime number and 0 if it isn't. This is the pseudo code given to us and I'm having trouble constructing it right.
1) Let variable div represent a possible divisor of x.
2) Set div = 2. Loop.
3) If x is divisible by div then return 0.
4) div++;
5) If div * div > x, return 1, else repeat loop. (go to step 3)
So far, this is what I got:
int isprime (int x)
{
int div = 2;
if (x % div ==0)
return = 0; div++
{
if ( div * div > x )
return = 1;
{
else
Did I use the return control right to determine if it's a prime number or not? Also, how would I link back to step 3 if div * div > x wasn't true. Thanks again!