2021/11/26
void swap(int* a, int* b)
{
int temp = *a;
*a = *b;
*b = temp;
}
#include<stdio.h>
main()
{
char a, b, c;
printf("please input three characters,system will sort them by ASC code size:\n");
scanf_s("%c %c %c", &a, 2, &b, 2, &c, 2);
if (a > b)
swap(&a, &b);
if (b > c)
swap(&b, &c);
if (a > c)
swap(&a, &c);
printf("the result is:%c %c %c\n", a, b, c);
}
这道题我在例题的专栏里提到了,那篇文章里的算法要低效无用的多,现在的解法要简洁的多,以后应该还有机会优化。