三个数比大小
将输入的任意3个整数从小到大输出,这三个数可以相等。 #include <stdio.h>int main(int argc, char const *argv[])
{
printf("Input 3 numbers: ");
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (a > b)
{
if (a > c)
{
if (b > c)
printf("%d, %d, %d", c, b, a);
else
printf("%d, %d, %d", b, c, a);
}
else
printf("%d, %d, %d", b, a, c);
}
else
{
if (a > c)
printf("%d, %d, %d", c, a, b);
else
{
if (b > c)
printf("%d, %d, %d", a, c, b);
else
printf("%d, %d, %d", a, b, c);
}
}
return 0;
} #include <stdio.h>
void sort(int *a, int *b){
if(*a > *b){
int temp = *a;
*a = *b;
*b = temp;
}
}
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
sort(&a, &b);
sort(&a, &c);
sort(&b, &c);
printf("%d %d %d", a, b, c);
return 0;
} #include <iostream>
using namespace std;
int main()
{
int m, n, x,temp;
cout << "本程序用于输入三个数,将其从小到大输出" << endl;
cout << "请输入三个整数:" << endl;
cin >> m >> n >> x;
if (m > n)
{
temp = m;
m = n;
n = temp;
}
if (n > x)
{
temp = n;
n = x;
x = temp;
}
cout << "三个数从小到大依次为:" << m <<" " << n << " " << x << endl;
}
页:
[1]