本题要求将输入的任意3个整数从小到大输出。
输入格式:
输入在一行中给出3个整数,其间以空格分隔。
输出格式:
在一行中将3个整数从小到大输出,其间以“->”相连。
输入样例:
4 2 8
输出样例:
2->4->8
#include <stdio.h>
void swap( int * x, int * y);
int main(){
int a, b, c, temp;
scanf("%d %d %d", &a, &b, &c);
//三个if用来排序,a最大,b其次,c最小。
if( a < b )
swap(&a, &b);
if( a < c )
swap(&a, &c);
if( b < c )
swap(&b, &c);
printf("%d->%d->%d", c, b, a);
return 0;
}
//swap函数用来交换两数的值
void swap( int * x, int * y){
int temp;
temp = *x;
*x = *y;
*y = temp;
}