我试图在 C 中编写一个代码来检查一个数字是否是奇数而不使用模运算符,但是在尝试编译时我一直遇到这个错误:
20:错误:预期的“)”
(我通过注释在代码块中指出了第 20 行。它在“else”之后)
#include <stdio.h>
/* check if number is odd or even */
/* something like n = 1111 1110 | x
* results in n = 1111 1111 if last bit of x is 1
* hence, if ~n = 0 then number is odd */
int truth;
int main()
{
void oddoreven(int 3);
if (truth)
printf("even");
else //this is line 20.
printf("odd");
return 0;
}
void oddoreven(int p)
{
truth = -126 | p;
truth = ~truth;
}