#include?<stdio.h>
int?main()
{
????int?score[10]={67,98,75,63,82,79,81,91,66,84};
????int?sum=0;
????int?i,j;
????int?temp;
????float?average;
????for(i=0;i<=9;i++)
????{
????????for(j=9;j>i;j--)
????????{
????????????if(score[j]>score[j-1])
????????????{
????????????????temp=score[j];
????????????????score[j-1]=score[j];
????????????????score[j]=temp;
????????????}
????????}
????????printf("%d?",score[i]);
????????sum+=score[i];
????}
????
????average=sum/10;
????printf("考試的總分=%d\n",sum);
????printf("考試的平均分=%f\n",average);
????printf("考試的最高分=%d\n",score[0]);
????printf("考試的最低分=%d\n",score[9]);
????return?0;
}
運行結果:98?98?91?91?91?91?91?91?84?84?...
怎么會把原來的數組數據給改了?
2018-07-17
在第二個for語句中,交換score[j-1]和score[j]的值時,score[j-1]的值被覆蓋了,應改為:temp=score[j-1];
2018-07-17
比較粗心,非常感謝