0
点赞
收藏
分享

微信扫一扫

【手把手带你刷好题】——29.从大到小输出(非力扣,作业)


【前言】


今天是刷题打卡第29天!

加油啦。


【手把手带你刷好题】——29.从大到小输出(非力扣,作业)_算法

原题:从大到小输出

题目描述:

写代码将三个整数数按从大到小输出。

示例:

输入:12 23 22
输出:23 22 12

思路:


本题主要记住一点:A中放的是最大值,B中放的是次大值,C中放的是最小值 


 代码执行:

将三个整数按从大到小输出
//本题需要注意的是对于if语句中的else语句的使用,注意不能随便使用哦
方法一
//#include<stdio.h>
//int main()
//{
// int a = 0;
// int b = 0;
// int c = 0;
// int temp = 0;
// printf("请输入三个整数:\n");
// scanf("%d %d %d", &a, &b, &c);
// //保证A位置放的是最大值,B中放的是次大值,C中放的是最小值
// if (a < b)
// {
// temp = a;
// a = b;
// b = temp;
// }
// if (a < c)
// {
// temp = a;
// a = c;
// c = temp;
// }
// if (b < c)
// {
// temp = b;
// b = c;
// c = temp;
// }
//
// printf("总大到小输出结果为:%d %d %d\n", a, b, c);
// return 0;
//}

//方法二:自定义函数实现
#include<stdio.h>


void tempNum(int* x, int* y)
{
int temp = *x;
*x = *y;
*y = temp;
}


int main()
{
int a = 0;
int b = 0;
int c = 0;
printf("请输入三个整数:\n");
scanf("%d %d %d",&a,&b,&c);
if (a < b)
{
tempNum(&a, &b);
}
if (a < c)
{
tempNum(&a, &c);
}
if (b < c)
{
tempNum(&b, &c);
}
printf("从大到小依次输出为:%d %d %d\n", a, b, c);
return 0;
}

结语


今天是刷题打卡第29天!

时间过得飞快,都快一个月啦,加油哦。


【手把手带你刷好题】——29.从大到小输出(非力扣,作业)_最小值_02 



举报

相关推荐

0 条评论