要么恶补,从头到类这里,起码基本知识补一遍
要么放弃,尽快转专业
#include <stdio.h> #include <windows.h> #define STUDENT_NUM_MAX 100 typedef struct { int cLanguage; int math; int culture; int totalScore; float average; } Student; int main() { int i = 0, j = 0, err = 0; int stuNum = 0, //学生总人数 allSubTotal = 0, //班级总分 allCLanguageTotal = 0, //C语言总分 allMathTotal = 0, //数学部分 allCultureTotal = 0; //文化基础部分 float allSubAvg = 0, //班级平均分 allCLanguageAvg = 0, //班级C语言平均分 allMathAvg = 0, //班级数学平均分 allCultureAvg = 0, //班级文化基础平均分 temp = 0; Student student[STUDENT_NUM_MAX]; while(err != 1) { printf("请输入班级总人数:"); err = scanf("%d", &stuNum); if (stuNum <0 || stuNum >STUDENT_NUM_MAX ) err = 0; fflush(stdin); } for (i=0; i < stuNum; i++) { err = 0; while(err != 3) { printf("请输入第 %d 个学生的成绩(C语言、数学、文化基础):", i + 1); err = scanf("%d%d%d", &student[i].cLanguage, &student[i].math, &student[i].culture); if (student[i].cLanguage < 0 || student[i].math < 0 || student[i].culture < 0) err = 0; if (student[i].cLanguage >100 || student[i].math > 100 || student[i].culture > 100) err = 0; fflush(stdin); } /*--------------个人项计算--------------*/ student[i].totalScore = student[i].cLanguage + student[i].math + student[i].culture; //总分 student[i].average = (float) student[i].totalScore / (float) 3; //平均分 /*--------------班级项计算--------------*/ allSubTotal += student[i].totalScore; //全部学科总分 allCLanguageTotal += student[i].cLanguage; //C语言总分 allMathTotal += student[i].math; //数学总分 allCultureTotal += student[i].culture; //文化总分 } /*--------------班级项计算--------------*/ allSubAvg = (float) allSubTotal / (float) stuNum; //班级平均分 allCLanguageAvg = (float) allCLanguageTotal / (float) stuNum; //班级C语言平均分 allMathAvg = (float) allMathTotal / (float) stuNum; //班级数学平均分 allCultureAvg = (float) allCultureTotal / (float) stuNum; //班级文化基础平均分 printf("\n===========班级统计信息===========\n"); printf("总分:\t\t\t%d\n\ 平均分:\t\t\t%.2f\n\ C语言平均分:\t\t%.2f\n\ 数学平均分:\t\t%.2f\n\ 文化基础平均分:\t\t%.2f\n", allSubTotal, allSubAvg, allCLanguageAvg, allMathAvg, allCultureAvg); //根据个人平均分降序排列 for (i=0; i<stuNum-1; i++) { for (j=0; j<stuNum-1-i; j++) { if (student[j].average < student[j+1].average) { temp = student[j].average; student[j].average = student[j+1].average; student[j+1].average = temp; } } } printf("\n==========个人平均分排序==========\n"); for(i=0; i<stuNum; i++) { printf("%.2f\n", student[i].average); } system("pause"); return 0; }