编程判断输入整数的正负性和奇偶性。 **输入格式要求:"%d" 提示信息:"Input m:" **输出格式要求: 如果是负偶数,则输出"%d is a negative even\n" 如果是负奇数,则输出"%d is a negative odd\n" 如果是正偶数,则输出"%d is a positive even\n" 如果是正奇数,则输出"%d is a positive odd\n" 如果是0,则输出"%d is zero. It is an even\n" 程序运行示例1: Input m:6↙ 6 is a positive even 程序运行示例2: Input m:0↙ 0 is zero. It is an even
时间: 2023-07-05 14:32:21 浏览: 63
从键盘任意输入一个整数,编程判断它的奇偶性。要求输入变量定义为int类型且由用户从键盘输入。
5星 · 资源好评率100%
下面是C语言的实现代码:
```c
#include <stdio.h>
int main() {
int m;
printf("Input m:");
scanf("%d", &m);
if (m == 0) {
printf("%d is zero. It is an even\n", m);
}
else if (m > 0) {
if (m % 2 == 0) {
printf("%d is a positive even\n", m);
}
else {
printf("%d is a positive odd\n", m);
}
}
else {
if (m % 2 == 0) {
printf("%d is a negative even\n", m);
}
else {
printf("%d is a negative odd\n", m);
}
}
return 0;
}
```
程序使用了if语句进行条件判断,首先判断m是否等于0,如果是则输出"0 is zero. It is an even"。否则,再分别判断m的正负性和奇偶性。如果m为正偶数,输出"%d is a positive even",如果m为正奇数,输出"%d is a positive odd"。如果m为负偶数,输出"%d is a negative even",如果m为负奇数,输出"%d is a negative odd"。
阅读全文