选择排序哪里有错误
#include<stdio.h>#define N 40
int Readscore(int score[]);
void Datasort(int score[],int n);
void printscore(int score[],int n);
int main()
{
int score[N],n;
n=Readscore(score);
printf("total students are %d\n",n);
Datasort(score,n);
printf("sorted scores:");
printscore(score,n);
return 0;
}
int Readscore(int score[])
{
int i=-1;
do{
i++;
printf("input score:");
scanf("%d",&score[i]);
}while(score[i]>=0);
return i;
}
void Datasort(int score[],int n)
{
int i,j,k,temp;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(score[j]>score[i])
{
k=j;
}
}
if(k!=i)
{
temp=score[i];
score[i]=score[j];
score[j]=temp;
}
}
void printscore(int score[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%4d",score[i]);
}
printf("\n");
}