#include<stdio.h> //输出最大的数 方法1
int main()
{
int a, b, c, d;
printf("请输入三个数:");
scanf_s("%d,%d,%d", &a, &b, &c);
if (a < b)
{
d = a;
a = b;
b = d; //1.如果a小于b将a的值赋给b,b的值赋给a //如果a大于b则跳转到下一步
}
if (a < c) //2.如果a小于c将a的值赋给c,c的值赋给a //如果a大于b则跳转到下一步
{
d = a;
a = c;
c = d;
} //1.2.是确保a大于b、c,
printf("最大的数为:%d", a);
return 0;
#include<stdio.h> //输出最大数 方法2
int main()
{
int a, b, c;
printf("请输入三位数");
scanf_s("%d %d %d", &a, &b, &c);
if ((a > b && a > c))
printf("您输入的%d为最大值", a);
else if ((b > a && b > c))
printf("您输入的%d为最大值", b);
else
printf("您输入的%d为最大值", c);
return 0;
}
#include<stdio.h> //输出最大数 方法3 关系式1?关系式2:关系式3 普通写法
int main()
{
int a, b, c;
scanf_s("%d %d %d", &a, &b, &c);
(a > b && a > c) ? printf("最大数为:%d",a) : 0;
(b > a && b > c) ? printf("最大数为:%d",b) : 0;
(c > b && c > a) ? printf("最大数为:%d",c) : 0;
return 0;
}
#include<stdio.h> //输出最大数 方法4 关系式1?关系式2:关系式3 嵌套写法
int main()
{
int a, b, c;
scanf_s("%d %d %d", &a, &b, &c);
(a > b && a > c) ? printf("最大数为:%d", a) :(b > a && b > c) ? printf("最大数为:%d", b) : (c > b && c > a) ? printf("最大数为:%d", c) : 0;
return 0;
}
#include<iostream>
using namespace std;
//编写一个c程序,输入a,b,c三个值,输出其中最大者。 //输出最大数 方法5 和方法2异曲同工
int main()
{
int a, b, c, max;
cin >> a >> b >> c;
max = a;
if (b > max && b > c)
{
max = b;
cout << max << endl;
}
else if (c > max && c > b)
{
max = c;
cout << max << endl;
}
else
{
cout << max << endl;
}
return 0;
}
喜欢记得点个收藏关注