【发布时间】:2021-05-23 07:36:02
【问题描述】:
我正在编写这个程序来查找单个数字中的两位数奇数,但我被卡住了。
例如- 在数字 56789 中有两个两位数的奇数:67 和 89。我为此编写了代码:
#include<stdio.h>
#include<conio.h>
int main()
{
int num,rem=0;
int odd=0;
printf("Enter a number: ");
scanf("%d",&num);
while(num>0)
{
rem=(num%100);
printf("%d\n",rem);
if(rem%2!=0)
{
odd++;
}
num=num/10;
}
printf("Odd digits count is: %d",odd);
return 0;
}
这是我的问题:
预期输出: 67 89 奇数总数:2个
【问题讨论】:
-
请注意,
conio.h不可移植,在这里完全没有必要。你为什么需要它?我建议删除该包含。 -
我们总是被告知 stdio.h 和 conio.h 是齐头并进的。谢谢,从现在开始我会记住的。
-
请不要以图片形式发布文字
-
conio.h从来都不是C标准包含文件;这将限制您的程序将在其上编译的计算机。除非您需要它的系统相关功能,否则最好不要包含它。
标签: c