将三个数从大到小输出,可以将这三个数两两相互比较,将较大的数移到前面将较小的数移到后面然后按顺序输出。
代码如下:
int main()
{
int a, b, c;
int tem = 0;
printf(“请输入三个数:”);
scanf("%d%d%d", &a, &b, &c);
if (a < b)
{
tem = a;
a = b;
b = tem;
}
if (a < c)
{
tem = a;
a = c;
c = tem;
}
if (b < c)
{
tem = b;
b = c;
c = tem;
}
printf("%d %d %d", a, b, c);
system(“pause”);
return 0;
}
输出结果:
将三个数按从大到小输出
最新推荐文章于 2023-04-26 15:34:52 发布