- 从数学角度分析,能被2整除的数为偶数,不能被2整除的数为奇数。
- 由此,输入一个整数N,比较其模除2的结果,为0则是偶数,返回0;不为0,则为奇数,返回1。
-
#include <stdio.h> /*奇偶判断函数 偶数返回0,奇数返回1*/ int judge_odd(int n); int main() { int N; int j; scanf("%d",&N); j = judge_odd(N); if(0 == j) printf("N为偶数\n"); else printf("N为奇数\n"); return 0; } int judge_odd(int n) { int i = 0; i = n % 2; if(0 == i) return 0; else return 1; }
10-02
1357
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-24
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交