题目
解决代码及点评
这道题考察对条件分支和赋值的灵活应用
正常思维
如果 a>b and a>c 那么a最大
如果b>c and b>a 那么b最大
如果c>a and c>b 那么c最大
但是以上写法判断多,代码复杂
简单的做法是:
如果 a < b 那么 a = b
如果 a < c 那么 a = c
最后a是最大值
#include <stdio.h>
#include <stdlib.h>
void main()
{
int a,b,c;
printf("please input a,b,c like a,b,c\n");
scanf_s("%d,%d,%d",&a,&b,&c);
if (a<b)
{
a=b;
}
if (a<c)
{
a=c;
}
printf("\n最大数字为%d",a);
system("pause");
}
代码下载及其运行
代码下载链接:
http://download.****.net/detail/yincheng01/6640573
解压密码为c.itcast.cn
下载解压后用VS2013打开工程文件 0201.vcxproj
点击 “本地Windows调试器” 执行
程序运行结果
输入三个数之后,程序输出最大值