c++选择法排序

// exam.cpp: 定义控制台应用程序的入口点。
//

#include “stdafx.h”
#include
using namespace std;
int main()
{
int i,j,temp,k,a[5];
for (i = 0; i < 5; i++)
{
cin >> a[i];
}
for (i = 0; i < 4; i++)
{
k = i;
for (j = i + 1; j < 5; j++)
{
if(a[k]>a[j])
{
k = j;
}
}
temp = a[i];
a[i] = a[k];
a[k] = temp;
}
for (i = 0; i < 5; i++)
{
cout << a[i] << " ";
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42706538/article/details/84872741