您的位置:首页 > 其它

12.1

2013-10-05 12:34 337 查看
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的数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: