第7讲 项目2----求三个数中的最大值
2015-10-18 10:24
197 查看
任务和代码:
运行结果:
知识点总结:
if……else……中嵌套if……else……时,需要知道程序的执行顺序
心得:
这个程序题,如果不嵌套if……else……可以这样走
if(a<b)
{max = b;}
else
{max = a ;}
if(max <c)
{max = c ;}
printf("最大数为%d\n",max);
/* *Copyright (c)2015 CSDN学院 *All rights reserved *文件名字:main.c *作者:zzhou *完成日期:2015年10月17日 *版本号:V1.0 * *问题描述:输入3个整数,输出其中的最大值 *程序分析:利用if嵌套,先判断a<b,在条件成立的情况下,再对b、c的关系比较 */ #include <stdio.h> #include <stdlib.h> int main() { int a, b ,c ; int temp ; printf("请输入3个整数\n"); scanf("%d %d %d",&a,&b,&c); if(a<b) { if(b<c) { temp = c ; } else { temp = b ; } } else { if(a<c) { temp = c ; } else { temp = a ; } } printf("%d、%d、%d、中最大的数是 %d\n",a,b,c,temp); return 0; }
运行结果:
知识点总结:
if……else……中嵌套if……else……时,需要知道程序的执行顺序
心得:
这个程序题,如果不嵌套if……else……可以这样走
if(a<b)
{max = b;}
else
{max = a ;}
if(max <c)
{max = c ;}
printf("最大数为%d\n",max);
相关文章推荐
- 怎样利用模板拼接字符串
- storm集群搭建
- mysql中如何判断是否支持分区
- 统计一个字符串中每个字母是否只出现了一次
- 二维数组的动态开辟
- Java、PHP训练场地选择成都传祺播客
- 人生感悟
- html5-svg标签使用基础三
- 在linux上搭建gtest
- 面向对象第一次实验参考代码
- 地址/数据/控制总线原理讲解
- 应用层、表示层、会话层相关知识
- 内存管理算法
- 【hihocoder】1094. lost in the City
- linux读书笔记3
- 安装ConEmu
- 开源UWP总结
- c字符串的处理
- LeetCode OJ:Delete Node in a Linked List(链表节点删除)
- M3U8文件简介