标签:temp for alt logs com img image es2017 png
#include<stdio.h>
#include<math.h>
//冒泡法排序
void main()
{
int a[7] = {4,5,6,7,9,2,1};
int temp;
for (int j = 0; j < 7; j++)
{
for (int i = 0; i < 6-j; i++)
{
if (a[i]> a[i+1])
{
temp = a[i + 1];
a[i + 1] = a[i];
a[i] = temp;
}
}
}
for (int i = 0; i<7; i++)
{
printf("%ld\n", a[i]);
}
while (1);
}
结果:
另一种排序:
#include<stdio.h>
#include<math.h>
//冒泡法排序
void main()
{
int a[7] = {4,5,6,7,9,2,1};
int temp;
for (int i = 0; i<7; i++)
{
for (int j = i+1; j < 7; j++)
{
if (a[i] > a[j])
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
for (int i = 0; i<7; i++)
{
printf("%ld\n", a[i]);
}
while (1);
}
标签:temp for alt logs com img image es2017 png
原文地址:http://www.cnblogs.com/panyani-532355476/p/7801003.html