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

37 lines
791 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 编写程序键盘输入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;
}