学生成绩处理系统
来源:互联网 发布:淘宝卖汽车用品怎么样 编辑:程序博客网 时间:2024/04/29 20:16
#include <stdio.h>#include <stdlib.h>#include <math.h>void input_score(int s[], int n);//将小组中n名同学的成绩输入数组sint get_max_score(int s[], int n);//返回数组s中n名同学的最高成绩值int get_min_score(int s[], int n);//返回数组s中n名同学的最低成绩值double get_avg_score(int s[], int n);//返回数组s中n名同学的平均成绩值double get_stdev_score(int s[], int n);//返回数组s中n名同学成绩值的标准偏差int count(int x, int s[], int n);//返回在数组s中n名同学中有多少人得x分(实参给出最高/低时,可以求最高/低成绩的人数)void output_index(int x, int s[], int n);//在函数中输出数组s中n名同学中得x分的学号(下标)int main( ){ int score[50]; //将score设为局部变量,通过数组名作函数参数,传递数组首地址,在函数中操作数组 int num; //小组人数也设为局部变量,将作为函数的实际参数 int max_score,min_score; printf("小组共有多少名同学? "); scanf("%d", &num); printf("请输入学生成绩:\n"); input_score(score, num); //要求成绩在0-100之间 max_score=get_max_score(score, num); printf("最高成绩为:%d,共有 %d 人\n", max_score, count(max_score, score, num )); min_score=get_min_score(score, num); printf("最低成绩为:%d,共有 %d 人\n", min_score, count(min_score,score, num )); printf("平均成绩为:%.2f\n", get_avg_score(score, num)); printf("标准偏差为:%.2f\n",get_stdev_score(score, num)); printf("获最高成绩的学生(学号)有:"); output_index(max_score,score, num); printf("\n获最低成绩的学生(学号)有:"); output_index(min_score,score, num); printf("\n"); return 0;}void input_score(int s[], int n){ int i; for(i=0; i<n; i++) { printf("第 %d 名学生成绩为:",i+1); scanf("%d",&s[i]); if(s[i]>100||s[i]<0) i--; }}int get_max_score(int s[], int n){ int i; int max=-1; for(i=0; i<n; i++) { if(s[i]>max) max=s[i]; } return max;}int get_min_score(int s[], int n){ int i; int min=101; for(i=0; i<n; i++) { if(s[i]<min) min=s[i]; } return min;}double get_avg_score(int s[], int n){ double sum=0; int i; for(i=0; i<n; i++) sum+=s[i]; return (sum/n);}double get_stdev_score(int s[], int n){ int i; double S=0; for(i=0; i<n; i++) S=S+(get_avg_score(s,n)-s[i])*(get_avg_score(s,n)-s[i]); return sqrt(S/(n-1));}int count(int x, int s[], int n){ int i,a=0; for(i=0; i<n; i++) { if(s[i]==x) a++; } return a;}void output_index(int x, int s[], int n){ int i; for(i=0; i<n; i++) { if(s[i]==x) printf("%d ",i+1); }}
运行结果:
1 0
- 学生成绩处理系统
- 学生成绩处理系统
- 学生成绩处理
- 类 处理学生成绩
- 一组学生成绩处理
- 学生成绩的处理
- 学生成绩处理
- 学生成绩处理
- 处理学生成绩
- 学生成绩的处理
- 学生成绩处理
- 学生成绩处理
- 学生成绩处理
- 学生成绩处理
- 13学生成绩处理
- 学生成绩处理程序
- 20-学生成绩处理
- 学生成绩的处理
- http协议之response案例一:请求重定向
- 生命倒计时-倒数9120日
- 最大k乘积
- 2017.01.01 学习日记-备忘录模式
- laragon 使用php5.* Service Apache can not start. Reason
- 学生成绩处理系统
- 06-JS特效-事件对象概述
- 机器学习简介
- 最小m段和
- 单例设计模式
- 07-JS特效-事件对象-pageY和screenY和clientY的区别
- 吼吼谢谢
- 08-JS特效-三大系列之client系列
- 告别2016,开启2017