Find this mistake(s) in the following code:
unsigned int i; for (i = 100; i >= 0; --i) printf(“%d\n”, i);
首先不能单单将"i<=0"改为"i>=0".
因为 i是无符号整数恒大于0.所以若改为"i>=0",只是将不进入循环改为了无限循环。
所以可以有两种改法:
1、
unsigned int i; for (i = 100; i > 0; --i)//输出100到1的数。</span> printf(“%d\n”, i);
2、
int i;//去掉无符号约束 for (i = 100; i >= 0; --i)//输出100到0的数。 printf(“%d\n”, i);