c練習題3:用指針比較3個數的大小

#include "stdio.h"


int main()
{
void swap(int *pt1, int *pt2);
void exchange(int *q1, int *q2, int *q3);


int a,b,c,*p1,*p2,*p3;
scanf("%d%d%d",&a,&b,&c);


p1=&a;
p2=&b;
p3=&c;

exchange(p1,p2,p3);

printf("%d %d %d\n",a,b,c);


return 0;
}
void swap(int *pt1, int *pt2)
{
int temp;
temp=*pt1;
*pt1=*pt2;
*pt2=temp;
}


void exchange(int *q1, int *q2, int *q3)
{
void swap(int *pt1, int *pt2);
if(*q1 < *q2)
swap(q1,q2);
if(*q1 < *q3)
swap(q1,q3);
if(*q2 < *q3)
swap(q2,q3);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章