c语言输入一个整数,判断是奇数还是偶数

如题所述

可以参考下面的代码:

#include "stdio.h

main() 

int x; 

printf("请输入一个整数"); 

scanf("%d",&x); 

if(x%2 == 0) printf("%d是偶数\n",x); 

else printf("%d是奇数\n",x); 

}

扩展资料:

C语言函数

double ceil(double x) 返回不小于x的最小整数

double floor(double x) 返回不大于x的最大整数

void srand(unsigned seed) 初始化随机数发生器

log()函数:返回x的自然对数(以e为底的对数)

ldiv()函数:求两个数的商和余数(针对long类型)

ceil()函数:求不小于x的最小整数(向上取整)

floor()函数:求不大于x的最大整数(向下取整)

参考资料来源:百度百科-c语言

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-04-21
#include<stdio.h>
int main(){
int a;
printf("请输入一个整数:");
scanf("%d",&a);
if(a%2==0){
printf("输入的整数是偶数。");
}
else{
printf("输入的整数是奇数。");
}
return 0;
}
第2个回答  2018-04-21
#include <stdio.h>

int main()
{
int Integer;

int times = 0;
//支持 10 组测试
while(1)
{
scanf("%d", &Integer);

if (Integer % 2 == 0)
printf("%d 是偶数!\n", Integer);
else
printf("%d 是奇数!\n", Integer);

//记录测试次数
times++;
if (times == 10) break;
}

return 0;
}

//测试输出:
//10
//10 是偶数!
//0
//0 是偶数!
//- 1
//- 1 是奇数!