為什么沒有冒泡排序成功啊
int down()
? ? {
? ? ? ? int score[]={67,98,75,63,82,79,81,91,66,84};
? ? ? ? int j,k,a; ? ?//循環(huán)變量
? ? ? ? int top; ? ?//最高分
? ? ? ? int low; ? ?//最低分
? ? ? ? for(j=9;j>=0;j--)
? ? ? ? {
? ? ? ? ? ? for(k=0;k<=j;k++)
? ? ? ? ? ? if( score [j]> score [j+1] )
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int temp;
? ? ? ? ? ? ? ? temp=score[j];
? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=temp;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? printf("考試成績排序:\n");
2019-03-14
#include <stdio.h>
int main()
{
? ? int score[]={67,98,75,63,82,79,81,91,66,84};
? ? int sum=0;
? ? double index=0;
? ? int temp;
? ? for(int i=0;i<=9;i++)
? ? {
? ? ? ? sum+=score[i];
? ? ? ? index++;
? ? }
? ? printf("總分:%d\n",sum);
? ? printf("平均分:%0.2f\n",sum/index);
? ? for(int j=0;j<9;j++)
? ? for(int k=0;k<9-j;k++)
? ? {
? ? ? ? if(score[k]<score[k+1])
? ? ? ? {
? ? ? ? temp=score[k];
? ? ? ? score[k]=score[k+1];
? ? ? ? score[k+1]=temp;
? ? ? ? }
? ? }
? ? printf("最高分:%d\n",score[0]);
? ? printf("最低分:%d\n成績降序排列:",score[9]);
? ? for(int n=0;n<10;n++)
? ? printf("%d ",score[n]);
? ? return 0;
}
2019-03-12
int down()
? ? {
? ? ? ? int score[]={67,98,75,63,82,79,81,91,66,84};
? ? ? ? int j,k,a; ? ?//循環(huán)變量
? ? ? ? int top; ? ?//最高分
? ? ? ? int low; ? ?//最低分
? ? ? ? for(j=9;j>0;j--)
? ? ? ? {
? ? ? ? ? ? for(k=0;k<j;k++)
? ? ? ? ? ? if( score [j]> score [j+1] )
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int temp;
? ? ? ? ? ? ? ? temp=score[j];
? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=temp;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? printf("考試成績排序:\n");
把兩個(gè)for括號(hào)里面比較的等號(hào)去掉即可!
2019-03-12
在for(j=9;j>=0;j--)當(dāng)中j=8。
因?yàn)榈诙友h(huán)中k=0了,如果j=9則需要排十次序
一共十個(gè)成績,只需要拍九次