简单的程序不倒数 [英] simple program not counting down
本文介绍了简单的程序不倒数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是c语言的新手,我决定写这个程序,谁能告诉我为什么它不从输入的数字递减到0?
hi im very new to c and i decided to write this program, can anyone tell me why its not counting down from the number entered to 0?
#include <stdio.h>
int printloop(int k )
{
int b;
for (b = k; b < 0; b--)
printf("%d\n",b);
}
int main()
{
int c;
scanf("%d",&c);
if( c > '0' && c < '6')
printloop(c);
return 0;
}
推荐答案
以以下内容开始:
To start with:
if( c > '0' && c < '6')
>
c
是定义的整数,但是您将其与字符"0"&进行比较. ``6''.删除0和amp;附近的引号6
c
is an integer defined but you compare it with a character ''0'' & ''6''. Remove quotes around 0 & 6
因为在您的for (b = k; b < 0; b--)
中,您不允许它执行任何工作.
第二子句"b< 0"表示仅当b< b等于0时,该循环才会运行. 0.
由于您将b == k设置为大于0,因此循环将不会运行.
您的解决方案是for (b = k; b >= 0; b--)
Because in yourfor (b = k; b < 0; b--)
, you aren''t allowing it to do any work.
The second clause "b<0" indicates that this loop will only run if b < 0.
Since you set b == k which is greater than 0, the loop will not run.
Your solution isfor (b = k; b >= 0; b--)
这篇关于简单的程序不倒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文