C语言编程判断输入整数的正负性和奇偶性。 **输入格式要求:"%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 09:06:46 浏览: 96
以下是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;
}
```
代码思路解析:
1. 要求用户输入一个整数m,使用scanf函数实现。
2. 判断m是否为0。如果是0,则输出"%d is zero. It is an even\n"。
3. 判断m是否为正数。如果是正数,则判断m是否为偶数。如果是偶数,则输出"%d is a positive even\n",否则输出"%d is a positive odd\n"。
4. 如果m不是正数,则必定为负数。判断m是否为偶数。如果是偶数,则输出"%d is a negative even\n",否则输出"%d is a negative odd\n"。
阅读全文