Topic 12.1 Find the mistake(s) in the following code:
unsigned int i;
For(i=100;i>=0; --i)
Printf(“%d\n”,i);
// Two mistakes:
1) Unsigned int is always >=0. 虽然打0正确,但循环永远不会结束。
If truly wanted to print zero, should add an additional printf after the for loop
2) If print unsigned int, we should use %u
方法1:unsigned inti;
for(i=100;i>0;--i)
printf("%u\n",i);
方法2:inti;
for(i=100;i>=0;--i)
printf("%d\n",i);// 输出100到0的数