偶发现了一个四不像 排序
#include <stdio.h>int main(void)
{
int a[10] = {3,2,1,5,7,4,6,9,8,2};
int x, y, i, temp;
for (x = 0; x < 10; x++)
{
for (y = 0; y < 10; y++)
{
if(a[x] > a[y])
{
temp = a[y];
a[y] = a[x];
a[x] = temp;
}
}
for (i = 0; i < 10; i++)
printf("%d", a[i]);
printf("\n");
}
for (i = 0; i < 10; i++)
printf("%d", a[i]);
}
输出:9876543221
#include <stdio.h>
int main(void)
{
int a[10] = {3,2,1,5,7,4,6,9,8,2};
int x, y, i, temp;
for (x = 0; x < 10; x++)
{
for (y = x; y < 10; y++)
{
if(a[x] > a[y])
{
temp = a[y];
a[y] = a[x];
a[x] = temp;
}
}
for (i = 0; i < 10; i++)
printf("%d", a[i]);
printf("\n");
}
for (i = 0; i < 10; i++)
printf("%d", a[i]);
}
输出:1223456789
[ 本帖最后由 BlueGuy 于 2009-9-22 22:02 编辑 ]