C++ 代码比较三个数并排序 (从小到大)
好的,请参考以下 C++ 代码,它会比较 a、b 和 c 三个数,并按从小到大的顺序排列。
#include <iostream>
#include <algorithm>
int main() {
int a, b, c;
std::cout << '请输入三个整数:' << std::endl;
std::cin >> a >> b >> c;
// 使用std::sort函数对a、b、c进行排序
int arr[] = {a, b, c};
std::sort(arr, arr + 3);
std::cout << '按从小到大排序的结果为:' << std::endl;
for(int i = 0; i < 3; i++) {
std::cout << arr[i] << ' ';
}
std::cout << std::endl;
return 0;
}
以上代码使用了std::sort函数对 a、b 和 c 进行排序,并按从小到大的顺序输出结果。请注意,代码中假设输入的是整数。
原文地址: https://www.cveoy.top/t/topic/SXQ 著作权归作者所有。请勿转载和采集!