I am supposed to write a function that determines if a number is prime or not. I return 1 if it is prime and 0 if it is not.
This is what I have so far:
I'm not quite sure what's wrong with that.Code:int isPrime ( int number ) { int i = 2; for(i=2; i<number ; i++) { if((number%i) == 0) { return 0; } else { return 1; } } }
Thanks
Edit: The function does work but I get the compiler warning, "control reaches end of non-void function" how could I get rid of that.
Edit Again: I figured it out, I just added an integer x and in one if statement I did x=0 rather than return 0 and for the other I did x = 1 rather than return 1, then at the end of the function I had return x.
Thanks anyways.