输入三个整数,要求按绝对值从小到大输出他们的值,用c语言编程
时间: 2024-03-30 17:19:29 浏览: 126
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
int abs_a = abs(a);
int abs_b = abs(b);
int abs_c = abs(c);
if (abs_a <= abs_b && abs_a <= abs_c)
{
printf("%d ", a);
if (abs_b <= abs_c)
{
printf("%d %d", b, c);
}
else
{
printf("%d %d", c, b);
}
}
else if (abs_b <= abs_a && abs_b <= abs_c)
{
printf("%d ", b);
if (abs_a <= abs_c)
{
printf("%d %d", a, c);
}
else
{
printf("%d %d", c, a);
}
}
else if (abs_c <= abs_a && abs_c <= abs_b)
{
printf("%d ", c);
if (abs_a <= abs_b)
{
printf("%d %d", a, b);
}
else
{
printf("%d %d", b, a);
}
}
return 0;
}
阅读全文