水草舞作品分析:C语言题目

来源:百度文库 编辑:高考问答 时间:2024/04/28 05:01:07
编一个函数sort,使用选择法将10个整数按由小到大的顺序排列。在main函数中输入这10个书,并输出排好序的数。

#include<stdio.h>

void sort(int *a)
{
int temp=0,i=0,sum=0,p=0,j=0;

for(i=0; i<10; i++)
{ p=i;
for(j=i+1;j<=9; j++)
{
if(a[p]>a[j])
{ p=j;
}
}

if(p!=i)
{
temp=a[p];
a[p]=a[i];
a[i]=temp;
}
}
}

void main()
{
int a[10]={9,2,5,3,1,2,4,7,8,0};
int i=0;
sort(a);
for(i=0;i<10;i++)
printf("%d ",a[i]);
}

http://www.softhouse.com.cn/html/200505/2005051714573600007406.html

我想这个网站很好,
我一直在用他学习

初学者吧!!!

要是初学者的话,你最好还是自己写,有不难,对你以后有好处啊!!!

排序问题有很多种解决方法,你最好自己分析一下。这个题目很容易。