用c语言编写程序输出某一同学10门课最高分科目及序号
时间: 2024-02-13 21:03:51 浏览: 26
好的,以下是用C语言编写的程序,可以输出某一同学10门课最高分科目及序号:
```c
#include <stdio.h>
int main() {
int scores[10], max_score = 0, max_index = 0;
// 读入10门课的分数
printf("请输入该同学的10门课分数:\n");
for (int i = 0; i < 10; i++) {
printf("第%d门课的分数:", i+1);
scanf("%d", &scores[i]);
}
// 找出最高分数及其序号
for (int i = 0; i < 10; i++) {
if (scores[i] > max_score) {
max_score = scores[i];
max_index = i;
}
}
// 输出最高分数及其序号
printf("该同学最高分数为:%d,对应的科目为第%d门课。\n", max_score, max_index+1);
return 0;
}
```
这个程序首先会让用户输入某一同学10门课的分数,然后找出最高分数及其序号,并输出结果。注意,这里的序号是从1开始的,而不是从0开始的。
相关问题
用c语言编写程序 输出你们全班50名同学的某门课的成绩的最低分。
好的,以下是用C语言编写程序,输出班级50名同学某门课程成绩最低分的代码示例:
```c
#include <stdio.h>
int main() {
int scores[50]; // 定义一个整型数组,用于存储50名同学的成绩
int min_score; // 定义一个整型变量,用于存储最低分
// 输入50名同学的成绩
for (int i = 0; i < 50; i++) {
printf("请输入第%d名同学的成绩:", i+1);
scanf("%d", &scores[i]);
}
// 计算最低分
min_score = scores[0]; // 先将最低分初始化为第一个同学的成绩
for (int i = 1; i < 50; i++) {
if (scores[i] < min_score) {
min_score = scores[i];
}
}
// 输出最低分
printf("全班%d名同学的最低分为:%d\n", 50, min_score);
return 0;
}
```
需要注意的是,以上代码中只是简单地演示了如何获取50名同学的成绩,并计算出最低分。在实际应用中,还需要考虑诸如输入错误、数据类型不匹配等异常情况的处理。
用C语言编写:从键盘输入某班某门课的成绩,编程打印最高分及学生序号
下面是用C语言编写的程序,实现从键盘输入某班某门课的成绩,并打印最高分及学生序号:
```c
#include <stdio.h>
#define MAX_STUDENT 100 // 最大学生数
int main()
{
int n; // 学生数
int scores[MAX_STUDENT]; // 成绩数组
int max_score = -1; // 最高分
int max_student_index; // 最高分学生的序号
printf("请输入学生数:");
scanf("%d", &n);
// 输入每个学生的成绩,并找出最高分
for (int i = 0; i < n; i++) {
printf("请输入第%d个学生的成绩:", i + 1);
scanf("%d", &scores[i]);
if (scores[i] > max_score) {
max_score = scores[i];
max_student_index = i;
}
}
// 打印最高分及学生序号
printf("最高分为%d,是第%d个学生的成绩\n", max_score, max_student_index + 1);
return 0;
}
```
运行程序,输入学生数和每个学生的成绩,程序会计算出最高分及对应的学生序号,并打印出来。