C++(10.5)

B A C D A B C C A B

40 3715 358 1523 5 4 8 2 0 13

cs 复制代码
#include <stdio.h>

int main() {
    float scores[10];  // 存储10个学生成绩
    int i, max_idx = 0;  // max_idx记录最高分序号
    float max_score;

    // 输入成绩
    printf("请输入10个学生的成绩:\n");
    for (i = 0; i < 10; i++) {
        scanf("%f", &scores[i]);
    }

    // 初始化最高分
    max_score = scores[0];

    // 查找最高分及序号
    for (i = 1; i < 10; i++) {
        if (scores[i] > max_score) {
            max_score = scores[i];
            max_idx = i;
        }
    }

    // 输出结果(序号从1开始)
    printf("最高成绩为:%.1f,对应序号为:%d\n", max_score, max_idx + 1);
    return 0;
}
cs 复制代码
#include <stdio.h>

#define STUDENT 5  // 学生数
#define COURSE 4   // 课程数

int main() {
    float scores[STUDENT][COURSE];  // 成绩数组
    float stu_avg[STUDENT] = {0};   // 学生平均分
    float course_avg[COURSE] = {0}; // 课程平均分
    int i, j;

    // 输入成绩
    printf("请输入%d个学生的%d门课程成绩(按行输入):\n", STUDENT, COURSE);
    for (i = 0; i < STUDENT; i++) {
        for (j = 0; j < COURSE; j++) {
            scanf("%f", &scores[i][j]);
            course_avg[j] += scores[i][j];  // 累加课程总分
            stu_avg[i] += scores[i][j];     // 累加学生总分
        }
        stu_avg[i] /= COURSE;  // 计算学生平均分
    }

    // 计算课程平均分
    for (j = 0; j < COURSE; j++) {
        course_avg[j] /= STUDENT;
    }

    // 输出课程平均分
    printf("\n各门课程的平均成绩:\n");
    for (j = 0; j < COURSE; j++) {
        printf("课程%d:%.1f  ", j + 1, course_avg[j]);
    }
    printf("\n");

    // 按学生平均分从高到低排序(冒泡排序)
    for (i = 0; i < STUDENT - 1; i++) {
        for (j = 0; j < STUDENT - 1 - i; j++) {
            if (stu_avg[j] < stu_avg[j + 1]) {
                // 交换学生平均分
                float temp_avg = stu_avg[j];
                stu_avg[j] = stu_avg[j + 1];
                stu_avg[j + 1] = temp_avg;
                // 交换对应学生的所有成绩
                for (int k = 0; k < COURSE; k++) {
                    float temp_score = scores[j][k];
                    scores[j][k] = scores[j + 1][k];
                    scores[j + 1][k] = temp_score;
                }
            }
        }
    }

    // 输出排序后的学生成绩及平均分
    printf("\n按学生平均分排序(从高到低):\n");
    for (i = 0; i < STUDENT; i++) {
        printf("学生%d成绩:", i + 1);
        for (j = 0; j < COURSE; j++) {
            printf("%.1f ", scores[i][j]);
        }
        printf("平均:%.1f\n", stu_avg[i]);
    }

    return 0;
}
相关推荐
mit6.8246 小时前
bfs|栈
算法
tobebetter95276 小时前
How to manage python versions on windows
开发语言·windows·python
9***P3347 小时前
PHP代码覆盖率
开发语言·php·代码覆盖率
CoderYanger7 小时前
优选算法-栈:67.基本计算器Ⅱ
java·开发语言·算法·leetcode·职场和发展·1024程序员节
jllllyuz8 小时前
Matlab实现基于Matrix Pencil算法实现声源信号角度和时间估计
开发语言·算法·matlab
稚辉君.MCA_P8_Java8 小时前
DeepSeek 插入排序
linux·后端·算法·架构·排序算法
多多*8 小时前
Java复习 操作系统原理 计算机网络相关 2025年11月23日
java·开发语言·网络·算法·spring·microsoft·maven
凌康ACG8 小时前
Sciter之c++与前端交互(五)
c++·sciter
p***43488 小时前
Rust网络编程模型
开发语言·网络·rust
ᐇ9598 小时前
Java集合框架深度实战:构建智能教育管理与娱乐系统
java·开发语言·娱乐