您的位置:首页 > 其它

第7讲 项目2----求三个数中的最大值

2015-10-18 10:24 197 查看
任务和代码:

/*
*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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: