编写函数 function1,用于将三个整数按从小到大排序。要求,该函数的输入参数为:int, int,int*,无返回值。在 main函数中调用时,如function1(&a,&b,&c),a、b 和 c 为三个整型变量,调用后,a 里存放最小的,b 里存放第二大的,c 里存放最大的。
3条回答 默认 最新
- 羽你同乐 2022-05-25 15:38关注
#include <stdio.h>
void function1(int* a,int* b,int* c);
int main()
{
int a = 3,b = 11,c = 2;
function1(&a,&b,&c);
printf("a = %d, b = %d, c = %d\n",a,b,c);
return 0;
}void function1(int* a,int* b,int* c)
{
int temp1,temp2,temp3;
if(*a < *b)
{
temp2 = *a;
if(temp2 > *c)
{
temp1 = *c;
*a = temp1;
temp3 = *b;
*c = temp3;
*b = temp2;
}else
{
if(*b < *c)
{
}else
{
temp3 = *b;
temp2 = *c;
*c = temp3;
*b = temp2;
}} }else { if(*a < *c) { temp1 = *b; temp2 = *a; *a = temp1; *b = temp2; }else { temp3 = *a; if(*b > *c) { temp1 = *c; *a = temp1; *c = temp3; }else { temp1 = *b; temp2 = *c; temp3 = *a; *c = temp3; *b = temp2; *a = temp1; } } }
}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 PADS Logic 原理图
- ¥15 PADS Logic 图标
- ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
- ¥20 气象站点数据求取中~
- ¥15 如何获取APP内弹出的网址链接
- ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
- ¥50 STM32单片机传感器读取错误
- ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
- ¥15 机器人轨迹规划相关问题
- ¥15 word样式右侧翻页键消失