C++ 数组最小值交换算法 - 代码示例与解释
#include<iostream> using namespace std;
int a[100], n;
int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; }
for (int i = 2; i <= n; i++)
{
if (a[1] > a[i])
{
int temp = a[1];
a[1] = a[i];
a[i] = temp;
}
}
for (int i = 1; i <= n; i++)
{
cout << a[i] << " ";
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/qf0k 著作权归作者所有。请勿转载和采集!