用c语言输入10个学生成绩,把及格成绩按降序输出。
时间: 2023-06-03 15:05:49 浏览: 38
好的,这个问题涉及计算机编程,我可以为您提供帮助。以下是实现此功能的 C 语言代码:
```c
#include <stdio.h>
int main() {
int scores[10];
int tmp;
// 输入成绩
for (int i = 0; i < 10; ++i) {
printf("请输入第%d个学生成绩:", i + 1);
scanf("%d", &scores[i]);
}
// 冒泡排序
for (int i = 0; i < 10 - 1; ++i) {
for (int j = 0; j < 10 - 1 - i; ++j) {
if (scores[j] < scores[j + 1]) {
tmp = scores[j];
scores[j] = scores[j + 1];
scores[j + 1] = tmp;
}
}
}
// 输出及格成绩
printf("及格成绩(降序)为:");
for (int i = 0; i < 10; ++i) {
if (scores[i] >= 60) {
printf("%d ", scores[i]);
}
}
printf("\n");
return 0;
}
```
您可以将此代码复制到 C 语言开发环境中运行,便可实现该功能。
相关问题
输入10学生成绩,把及格成绩按降序输出 用C语言表达
抱歉,我只能回答和程序开发相关的问题,无法回答其他问题。以下是C语言示例代码,用于输入10个学生成绩并将及格成绩进行降序输出:
```
#include <stdio.h>
int main() {
float grades[10];
float temp;
printf("请输入10个学生成绩:\n");
// 循环获取输入成绩
for(int i=0; i<10; i++) {
scanf("%f", &grades[i]);
}
// 冒泡排序法进行降序排序
for(int i=0; i<10; i++) {
for(int j=i+1; j<10; j++) {
if(grades[i] < grades[j]) {
temp = grades[i];
grades[i] = grades[j];
grades[j] = temp;
}
}
}
// 输出及格成绩
printf("及格成绩降序排列为:\n");
for(int i=0; i<10; i++) {
if(grades[i] >= 60) {
printf("%.2f\n", grades[i]);
}
}
return 0;
}
```
该程序利用冒泡排序法对成绩进行排序,然后输出及格成绩。
C语言输入10个学生成绩输出等级
以下是C语言输入10个学生成绩输出等级的示例代码:
```c
#include <stdio.h>
int main() {
int scores[10]; // 定义一个长度为10的整型数组,用于存储学生成绩
printf("请输入10个学生成绩:\n");
for (int i = 0; i < 10; i++) {
scanf("%d", &scores[i]); // 输入学生成绩
}
printf("学生成绩对应的等级为:\n");
for (int i = 0; i < 10; i++) {
int a = scores[i] / 10; // 将分数转化为0~10
switch (a) {
case 10:
case 9:
printf("A\n");
break;
case 8:
printf("B\n");
break;
case 7:
printf("C\n");
break;
case 6:
printf("D\n");
break;
default:
printf("E\n");
break;
}
}
return 0;
}
```
该程序首先定义了一个长度为10的整型数组,用于存储学生成绩。然后通过for循环,依次输入10个学生成绩。接着,再通过for循环,依次将每个学生成绩转化为等级,并输出对应的等级。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)