PTA 三个数比较大小##
本题要求将输入的任意3个整数从小到大输出。
输入格式:
输入在一行中给出3个整数,其间以空格分隔。
输出格式:
在一行中将3个整数从小到大输出,其间以“->”相连。
输入样例:
4 2 8
输出样例:
2->4->8
#include <stdio.h>
int swap(int*,int*);int swap(intx,inty){ int t; t=*x; *x=*y; *y=t;}int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); if(a<c&&c<b) { swap(&b,&c); } else if(c<a&&a<b) { swap(&a,&c); swap(&b,&c); } else if(b<a&&a<c) { swap(&a,&b); } else if(b<c&&c<a) { swap(&b,&c); swap(&a,&c); } else if(c<b&&b<a) { swap(&a,&c); } printf("%d->%d->%d",a,b,c); return 0; }