include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int a[7] = {2,4,3,6,5,8,7};//7个数组元素
int temp;中间变量
for (int i = 0; i < 7; i++)
{
for (int j = i+1; j < 7; j++)
{
if (a[i] > a[i + 1])
{
temp = a[i];
a[j] = a[i];//将数组的首地址赋值给下一个数组的首地址
a[i] = temp;
}
}
for (int i = 0; i < 7; i++)
{
printf("%d", a[i]);
}
}
system("pause");
}
#include<stdio.h>
using namespace std;
int main()
{
int a[7] = {2,4,3,6,5,8,7};//7个数组元素
int temp;中间变量
for (int i = 0; i < 7; i++)
{
for (int j = i+1; j < 7; j++)
{
if (a[i] > a[i + 1])
{
temp = a[i];
a[j] = a[i];//将数组的首地址赋值给下一个数组的首地址
a[i] = temp;
}
}
for (int i = 0; i < 7; i++)
{
printf("%d", a[i]);
}
}
system("pause");
}