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的数
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的数
相关文章推荐
- 例4-2
- 1.二元查找树转变成排序的双向链表
- Hibernate tutorial with Eclipse
- MySQL类型转换
- 计算机
- 由1-7的随机整数函数构造1-10随机整数函数
- vmware workstation 8安Centos6.2出现问题
- JQueryEasyUI easyui-datetimebox 取消用户输入
- Interface
- JQueryEasyUI layout显示不出来问题
- Ajax 在IE 10下不能正常工作一例
- 例4-1
- Android之Selector、Shape介绍
- Shell中同时读多个文件
- 解决:Determining IP Information for eth0...问题
- hibernate之HQL之full join和笛卡儿积
- 拥抱变化
- FCKEditor 中文字体添加与中文字体无效的解决方法
- C/C++ 编码规范
- Linux多线程──生产者消费者问题