1. 程式人生 > 其它 >編寫一main()函式,要求利用指標,實現從鍵盤輸入三個數,然後按照由小到大的順序輸出此三個數。

編寫一main()函式,要求利用指標,實現從鍵盤輸入三個數,然後按照由小到大的順序輸出此三個數。

技術標籤:c語言

#include<stdio.h>
int main()
{
  int a,b,c,t;
  int *p1=&a,*p2=&b,*p3=&c;
  printf("Input a,b,c:");
  scanf("%d,%d,%d",&a,&b,&c);
  if(*p1>*p2){t=*p1;*p1=*p2;*p2=t;}
  if(*p1>*p3){t=*p1;*p1=*p3;*p3=t;}
  if(*p2>*p3){t=*p2;*p2=*p3;
*p3=t;} printf("The result is:%d,%d,%d\n",*p1,*p2,*p3); }

在這裡插入圖片描述