提高篇第22-25课第二题
来源:互联网 发布:上海绿茶网络 编辑:程序博客网 时间:2024/06/05 10:40
#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++)scanf("%d", s + i);}int get_max_score(int s[], int n){int max=s[0];int i;for (i = 0; i < n; i++){if (s[i] >= max)max = s[i];}return max;}int get_min_score(int s[], int n){int min = s[0];int i;for (i = 0; i < n; i++){if (s[i] <= min)min = s[i];}return min;}double get_avg_score(int s[], int n){int sum = 0;int i;double avg;for (i = 0; i < n; i++)sum += s[i];avg = sum / n;return avg;}double get_stdev_score(int s[], int n){int i;double avg;double temp_sum=0,stdev;avg = get_avg_score(s, n);for (i = 0; i < n; i++)temp_sum += (s[i] - avg)*(s[i] - avg);stdev = sqrt(temp_sum / (n - 1));return stdev;}int count(int key, int s[], int n){int count = 0,i;for (i = 0; i < n; i++)if (s[i] == key)count++;return count;}void output_index(int key, int s[], int n){int i;for (i = 0; i < n; i++)if (s[i] == key)printf("%d,", i);}
0 0
- 提高篇第22-25课第二题
- 提高篇第2-5课第二题
- 提高篇第6-10课作业第二题
- 提高篇第20-21课第二题
- 提高篇第26-27课第二题
- 提高篇第28-31课第二题
- 提高篇第22-25课作业第一题
- 提高篇16-19第二题
- 第二章第22题
- 第32课第二题
- 第33课第二题
- 第34课第二题
- 第35课第二题
- 第36课第二题
- 第37课第二题
- 第39课第二题
- 第43课第二题
- 提高篇第2-5课第一题
- Html 表单实例--未加css
- 河南自闭症的治方法
- Oracle11g R2: Node Connectivity check failed解决办法
- C++中标准输入输出的格式控制 (十六进制输入输出,输出数据对齐)
- n条直线交点拟合求交点
- 提高篇第22-25课第二题
- HDU4407Sum 容斥定理
- C#小知识点
- How to install or upgrade UV4L on Raspbian (for the Raspberry Pi)
- GFW 小结
- Javascript高级程序设计(第三版) 数组
- 学习ASP.NET MVC5框架揭秘笔记-ASP.NET路由(十二)
- caffe loss
- 河南自闭症治疗去哪里好