程序:不妨按从小到大排序
#include <stdio.h>
int main ()
{
int a[10];
int i = 0;
int j = 0;
int t = 0;
printf ("input 10 numbers:");
for ( i = 0; i < 10; i++)
{
scanf ("%d",&a[i]);
}
for (i = 0; i < 9; i++)
for ( j = 0; j < 9 - i; j++)
if (a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
printf ("the sorted numbers:\n");
//"the sorted numbers"表示排序的数字
for (i =0; i < 10; i++)
printf ("%d\t", a[i]);
printf ("\n");
return 0;
}
输出结果:
input 10 numbers:11 2 3 5 34 6 78 9 12 62
the sorted numbers:
2 3 5 6 9 11 12 34 62 78
时间: 2024-10-10 13:48:26