C语言编程如何判断输入整数的正负性和奇偶性?

2024-11-30 01:45:30
推荐回答(2个)
回答1:

void main()
{
int num;
scanf("%d",&num);
if(num>0)
{printf("该数是正数\n;}
else
{printf("该数是负数\n;}
num=num%2;
if(num==0)
{prin订鸡斥课俪酒筹旬船莫tf("该数是偶数\n;}
else
{printf("该数是奇数\n;}

#include
main()
{
int x,y;
printf("Please input a integer:");      /*输入一个整数!*/
scanf("%d",x);
if(x<0)
printf("It's a negative number!");  /*输入的数是负数!*/
else
printf("It's a positive number!");  /*输入的数是正数!*/
y=x%2;
if(0==y)
printf("It's a even number!");      /*输入的数是偶数!*/
else
printf("It's a odd number!");       /*输入的数是奇数!*/
}

右边的是注释!

回答2:

#include
main()
{
int
x,y;
printf("Please
input
a
integer:");
/*输入一个整数!*/
scanf("%d",x);
if(x<0)
printf("It's
a
negative
number!");
/*输入的数是负数!*/
else
printf("It's
a
positive
number!");
/*输入的数是正数!*/
y=x%2;
if(0==y)
printf("It's
a
even
number!");
/*输入的数是偶数!*/
else
printf("It's
a
odd
number!");
/*输入的数是奇数!*/
}
右边的是注释!