題目:輸入3個數a,b,c,按大小順序輸出,
程式分析:利用指標方法,
實體:
1 # include<stdio.h> 2 3 void swap(int *, int *); 4 int main(void) 5 { 6 int a, b, c; 7 int *p1, *p2, *p3; 8 printf("輸入 a, b ,c:\n"); 9 scanf("%d %d %d", &a, &b, &c); 10 p1 = &a; 11 p2 = &b; 12 p3 = &c; 13 if(a>b) 14 swap(p1, p2); 15 if(a>c) 16 swap(p1, p3); 17 if(b>c) 18 swap(p2, p3); 19 printf("%d %d %d\n", a, b, c); 20 } 21 void swap(int *s1, int *s2) 22 { 23 int t; 24 t = *s1; *s1 = *s2; *s2 = t; 25 }
以上程式執行輸出結果為:
輸入 a, b ,c: 1 3 2 1 2 3
感謝你的閱讀,請用心感悟!希望可以幫到愛學習的你!!分享也是一種快樂!!!請接力,,,
點擊查看原文,謝謝!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/6553.html
標籤:C
上一篇:C 實戰練習題目65
