輸出最高的分數有這一段看不懂
int gao(int score[])
{
?int i;
?for(i=0;i<9;i++)
?{
?if(score[i]>score[i+1])
?score[i+1]=score[i];
?}
?printf("%d\n",score[i]);
}
int gao(int score[])
{
?int i;
?for(i=0;i<9;i++)
?{
?if(score[i]>score[i+1])
?score[i+1]=score[i];
?}
?printf("%d\n",score[i]);
}
2018-01-12
舉報
2018-01-23
//判斷語句里面的代碼錯了,要替換兩個元素的位置,需要一個中間變量(外面定義一個int temp),改成?
if(score[i]>score[i+1])
{ temp=score[i]; score[i]=score[i+1];score[i+1]=temp;
}
//這個排序一次是把最大數移動到了最后一個位置,所以最高分應該是arr[9]
//建議最好外部定義好常量N,例#define N 10,做為數組的長度,這樣這道題里面的最高分就是arr[N-1].
2018-01-14
if(score[i]>score[i+1]) //如果前一個數大于后一個;
?score[i+1]=score[i] //就把后面較小的那個數賦值給前一個;
以此類推:最小的數最終賦值到了第一個,然后輸出;
剩下四個在執行循環,選出最小的,再輸出;
最后就可以按照有小到大的順序輸出。