标题:选择排序哪里有错误
取消只看楼主
豆zi
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-12-9
结帖率:0
已结贴  问题点数:20 回复次数:0 
选择排序哪里有错误
#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");
    }

搜索更多相关主题的帖子: scores return include 
2013-12-09 22:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-424968-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.168732 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved