热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_63064634
何妨吟啸且徐行29
5 年前
trueweixin_63064634

#include<stdio.h>
int Read(int score[]);
void BubbleSort(int score[],int n);//冒泡法排序
void Print(int score[],int n);
#define N 40
int main(void)
{
int score[N],n;
n=Read(score);
printf("The number of the students is %d\n",n);
BubbleSort(score,n);
Print(score,n);
return 0;
}
int Read(int score[])
{
int i=-1;
do
{
i++;
printf("Input scores:");
scanf("%d",&score[i]);
}while(score[i]>=0);
return i;
}
void BubbleSort(int score[],int n) //降序排列 从高到低
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=1;j<j-i;j++)
{
if(score[j]>score[j-1])
{
temp=score[j];
score[j]=score[j-1];
score[j-1]=temp;
}
}
}
}
void Print(int score[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%d,",score[i]);
}
}

CSDN App 扫码分享
分享
1
点赞
打赏
  • 复制链接
  • 举报
下一条:
刚玩儿CSDN不久,感谢第一位关注我的粉丝!我会继续加油努力,产出更优秀的作品。
立即登录