十个数从小到大排序(C语言)
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[10] = {3,4,6,8,1,5,9,2,7,10};
int i,j,temp;
for(i=0;i<=9;i++)
{
for(j=i+1;j<=9;j++)
{
if(str[i] > str[j])
{
temp = str[j];
str[j] = str[i];
str[i] = temp;
}
}
}
printf("从小到大排序为:\n");
for(i=0;i<=9;i++)
{
printf("%d ",str[i]);
}
system("pause"); // 防止运行后自动退出,需头文件stdlib.h
return 0;
}