输入三个整数按由小到大的顺序输出,用c++写代码
时间: 2023-09-01 22:11:41 浏览: 192
好的,下面是c语言的代码:
```
#include <stdio.h>
int main()
{
int a, b, c;
printf("请输入三个整数:");
scanf("%d %d %d", &a, &b, &c);
if (a > b) {
int temp = a;
a = b;
b = temp;
}
if (a > c) {
int temp = a;
a = c;
c = temp;
}
if (b > c) {
int temp = b;
b = c;
c = temp;
}
printf("从小到大排序为:%d %d %d\n", a, b, c);
return 0;
}
```
希望能对您有所帮助。接下来请问您还有其他问题吗?
相关问题
c++输入三个整数,按从大到小的顺序输出
可以使用数组来存储这三个整数,然后使用排序算法进行排序,最后按照从大到小的顺序输出即可。以下是一个示例代码:
```c++
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int nums[3];
for (int i = 0; i < 3; i++) {
cin >> nums[i];
}
sort(nums, nums + 3);
for (int i = 2; i >= 0; i--) {
cout << nums[i] << " ";
}
cout << endl;
return 0;
}
```
输入三个整数后,程序会先将它们存储到数组 `nums` 中,然后使用 `sort` 函数对数组进行排序。最后,从大到小地输出排序后的数组即可。
输入三个整数x,y,z,请把这三个数按由小到大的顺序输出 c++代码
以下是输入三个整数并按从小到大排序输出的C++代码:
```c++
#include <iostream>
using namespace std;
int main()
{
int x, y, z;
cin >> x >> y >> z;
if (x > y)
{
int temp = x;
x = y;
y = temp;
}
if (x > z)
{
int temp = x;
x = z;
z = temp;
}
if (y > z)
{
int temp = y;
y = z;
z = temp;
}
cout << x << " " << y << " " << z << endl;
return 0;
}
```