here is code.
int main(int argc, const char * argv[])
{
@autoreleasepool {
int x,y;
//BOOL divsibleYESOrNo;
NSLog(@"enter two number for test it\n");
scanf("%i %i",&x,&y);
if ( x%y ==0 ) {
NSLog(@"YES,it can be");
}
else if (x%y !=0) {
NSLog(@"no there cant.");
}
else
NSLog(@"zero is not allow");
}
return 0;
}
this code can not detect if the user input two zero.
how can I modify this code that can detect the input values are zero?
Thanks
Anything % 0 is undefined, so you’ll need to add a check for y == 0 before your other if statements. It has to be the first if statement in order to make sure it gets evaluated; otherwise one of your other statements will catch it erroneously first.