#include <stdio.h>
void main()
{
int a, b, c;
printf("input a,b,c\n");
scanf_s("%d,%d,%d", &a, &b, &c);
if (a > b)
{
a = a ^ b;
b = b ^ a;
a = a ^ b;//b>a
}
if (a > c)
{
a = a ^ c;
c = c ^ a;
a = a ^ c;//c>a a最小
}
if (b > c)
{
b = b ^ c;
c = c ^ b;
b = b ^ c;//c最大
}
printf("max=%d,%d,min=%d", c, b, a);
}
/*
另一种思想
#include<stdio.h>
void main()
{
int a, b, c,max,min,middle;
scanf_s("%d,%d,%d", &a, &b, &c);
max = a > b ? (a > c ? a : c) : (b > c ? b : c);
min = a < b ? (a<c?a:c) : (b<c?b:c);
middle = a > b ? (b > c ? (b) : (c > a ? a : c)) : (a > c ? (a) : (c > b ? b : c));
printf("max=%d,middle=%d,min=%d", max, middle, min);
}*/
小白:判断三个数大小的几种方法(持续更新)
最新推荐文章于 2022-07-07 17:57:00 发布