warning (apparently control is not odd or even :P ) . How do I suppress this warning? I found out about #pragma GCC diagnostic ignored "-Wwarningflag" but I don't know what warningflag would be in this case, and I don't know where to look (Google wasn't helpful) .
the easy solution is to just get rid of your redundant condition:
1 2 3 4 5 6 7
int negOneToTheXthPower (long x)
{
if (x % 2 == 0)
return 1 ;
else // no if() here
return -1 ;
}
Not only is this less code for you to type, but it's also possibly faster since the additional check can be omitted, and it reduces duplicate code (duplicate code = evil)