Description
从键盘输入三个字符,用空格隔开,使用带参宏定义1中SWAP,将三个字符按从大到小的顺序排序输出。
宏定义1:#define SWAP(a, b, t) { t=a; a=b; b=t; }
请尝试,如果用宏定义2中的SWAP,主函数需要如何修改才能得到正确结果?
宏定义2:#define SWAP(a, b, t) t=a; a=b; b=t;
Input
输入三个字符,用空格隔开
Output
输出占一行,包含三个字符,用空格隔开
Sample Input
w a q
Sample Output
w q a
HINT
Source
#include<stdio.h>
#define SWAP(a, b, t) t=a; a=b; b=t;
int main()
{
char a,b,c,t,i;
scanf("%c %c %c",&a,&b,&c);
for(i=0; i<3; i++)
{
if(a<b)
{
{SWAP(a,b,t);}
}
else if(b<c)
{
{SWAP(b,c,t);}
}
else if(a<c)
{
{SWAP(a,c,t);}
}
}
printf("%c %c %c\n",a,b,c);
return 0;
}