qfedu-c-level/day6/homework/h2.c

37 lines
791 B
C
Raw Normal View History

2023-07-11 01:33:28 +08:00
// 编写程序键盘输入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;
}