沙河口区实验小学三年五班有54名学生,期末考试科目为数学、语文、英语,现需要统计该班学生成绩,要求:按学号输入学生各科成绩,输出学生的学号、总分、平均分,请选择合适的程序设计语言完成。(学号为1-54)
3条回答 默认 最新
个人练习生xx 2023-05-16 14:52关注上代码
#include <stdio.h> int main() { int scores[54][3]; // 存储54个学生3门科目的成绩 for (int i = 1; i <= 54; i++) { // 学号1-54 printf("请输入学号%d的数学成绩: ", i); scanf("%d", &scores[i-1][0]); printf("请输入学号%d的语文成绩: ", i); scanf("%d", &scores[i-1][1]); printf("请输入学号%d的英语成绩: ", i); scanf("%d", &scores[i-1][2]); } for (int i = 1; i <= 54; i++) { int sum = 0; for (int j = 0; j < 3; j++) { sum += scores[i-1][j]; // 求总分 } float avg = sum / 3.0; // 求平均分 printf("学号%d的总分是%d,平均分是%.2f\n", i, sum, avg); } }scores = {} # 存储学生成绩,key是学号,value是各科成绩列表 for i in range(1, 55): # 学号1-54 math = int(input(f'请输入学号{i}的数学成绩: ')) chinese = int(input(f'请输入学号{i}的语文成绩: ')) english = int(input(f'请输入学号{i}的英语成绩: ')) scores[i] = [math, chinese, english] # 存储各科成绩 for i in range(1, 55): sum_score = sum(scores[i]) # 求总分 avg_score = sum_score / 3 # 求平均分 print(f'学号{i}的总分是{sum_score},平均分是{avg_score}') # 输出学号、总分、平均分评论 打赏 举报解决 2无用