37 lines
791 B
C
37 lines
791 B
C
|
// 编写程序,键盘输入10位学生的成绩,按大到小排序并输出
|
|||
|
#include <stdio.h>
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
float stuScore[10];
|
|||
|
int i = 0;
|
|||
|
while (i < 10)
|
|||
|
{
|
|||
|
printf("请输入第%d位学生的成绩: ", i + 1);
|
|||
|
scanf("%f", &stuScore[i]);
|
|||
|
i++;
|
|||
|
}
|
|||
|
|
|||
|
float temp;
|
|||
|
int len = sizeof(stuScore) / sizeof(float);
|
|||
|
for (int i = 0; i < len - 1; i++)
|
|||
|
{
|
|||
|
for (int j = 0; j < len - i - 1; j++)
|
|||
|
{
|
|||
|
if (stuScore[j] < stuScore[j + 1])
|
|||
|
{
|
|||
|
temp = stuScore[j];
|
|||
|
stuScore[j] = stuScore[j + 1];
|
|||
|
stuScore[j + 1] = temp;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
for (int i = 0; i < len; i++)
|
|||
|
{
|
|||
|
printf("%.2f ", stuScore[i]);
|
|||
|
}
|
|||
|
printf("\n");
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|