两个题目:
- 找出三个数的最大值
- 比较三个数并按由大到小的次序排列输出
- 方法一:使用if语句,创建中间变量
//求三个整数的最大值
#include<stdio.h>
#include<stdlib.h>
int max_val(int a, int b, int c)
{
int tmp = a;
if (b > tmp)
{
tmp = b;
}
if (c > tmp)
{
tmp = c;
}
return tmp;
}
int main()
{
int a = 0, b = 0, c = 0;
printf("请输入三个数字:");
scanf("%d%d%d", &a, &b, &c);
printf("最大值为:%d\n", max_val(a, b, c));
system("pause");
return 0;
}