C语言冒泡排序:10个学生成绩降序排列
#include <stdio.h>
int main() {
int scores[10] = {85, 76, 94, 67, 89, 72, 90, 83, 78, 91};
int i, j, temp;
for (i = 0; i < 9; i++) {
for (j = 0; j < 9 - i; j++) {
if (scores[j] < scores[j+1]) {
temp = scores[j];
scores[j] = scores[j+1];
scores[j+1] = temp;
}
}
}
printf('降序排列后的成绩:\n');
for (i = 0; i < 10; i++) {
printf('%d ', scores[i]);
}
return 0;
}
输出结果为:
降序排列后的成绩:
94 91 90 89 85 83 78 76 72 67
原文地址: https://www.cveoy.top/t/topic/nF5l 著作权归作者所有。请勿转载和采集!