输入三个整数a,b,c要求按由大到小的顺序将其输出用函数实现
#include<stdio.h>
int main(){
void exchange(int *pt1,int *pt2,int *pt3);
int a,b,c;
int *p1,*p2,*p3;
printf("please input three numbers:");
scanf("%d,%d,%d",&a,&b,&c);
p1 = &a,p2 = &b,p3 = &c;
exchange(p1,p2,p3);
printf("the order is:%d,%d,%d\n",a,b,c);
return 0;
}
void exchange(int *pt1,int *pt2,int *pt3){
void swap(int *ptt1,int *ptt2);
if(*pt1<*pt2)swap(pt1,pt2);
if(*pt1<*pt3)swap(pt1,pt3);
if(*pt2<*pt3)swap(pt2,pt3);
}
void swap(int *ptt1,int *ptt2){
int temp;
temp = *ptt1;
*ptt1 = *ptt2;
*ptt2 = temp;
}
3122

被折叠的 条评论
为什么被折叠?



