#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<stdlib.h>
int main()
{
int a, b, c, t;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
if (a < b )
{
t = b;
b = a;
a = t;
}
if (a < c)
{
t = c;
c = a;
a = t;
}
if (b < c)
{
t = c;
c = b;
b = t;
}
printf("%d%d%d \n", a, b, c); //a必须为最大值a>b>c
system("pause");
return 0;
}
方法二(用函数来实现)
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<stdlib.h>
void Swap(int x,int y)
{
int tmp=x;
x=y;
y=tmp;
}
int main()
{
int a, b, c, t;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
if (a < b )
{
Swap(a,b);
}
if (a < c)
{
Swap(a,c);
}
if (b < c)
{
Swap(b,c);
}
printf("%d%d%d \n", a, b, c); //a必须为最大值a>b>c
system("pause");
return 0;
}
将三个数按从大到小输出。
猜你喜欢
转载自blog.csdn.net/qq_44828389/article/details/100610853
今日推荐
周排行