[問題] C語言 陣列問題
#include <stdio.h>
#define NUM 5
int main(void)
{
int test[NUM];
int tmp;
int i,j,s,t;
printf("請輸入%d個學生的分數 . \n", NUM);
for(i=0; i<NUM; i++){
scanf("%d", &test[i]);
}
for(s=0; s<NUM-1; s++){
for(t=s+1; t<NUM; t++){
if(test[t]> test[s]){
tmp = test[t];
test[t] = test[s];
test[s] = tmp;
}
}
}
for(j=0; j<NUM; j++){
printf("%d號學生的成績為%d分 . \n", j+1 , test[j]);
}
system("PAUSE");
return 0;
}
.....................................
小弟對於整個程式碼很茫然
for(s=0; s<NUM-1; s++){
for(t=s+1; t<NUM; t++){
if(test[t]> test[s]){
tmp = test[t];
test[t] = test[s];
test[s] = tmp;
即使配和書本還是不懂 為啥會自動把成績由大到小排序~~
請高手救命!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.115.86.142
→
06/21 00:02, , 1F
06/21 00:02, 1F
→
06/21 00:04, , 2F
06/21 00:04, 2F
→
06/21 00:04, , 3F
06/21 00:04, 3F
推
06/21 00:06, , 4F
06/21 00:06, 4F
→
06/21 00:22, , 5F
06/21 00:22, 5F
→
06/21 01:29, , 6F
06/21 01:29, 6F
→
06/21 08:40, , 7F
06/21 08:40, 7F
推
06/21 09:28, , 8F
06/21 09:28, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章