题干
请编写一个函数sum,函数的功能是:计算一个由结构体表示的包含多门课程成绩组成的学生的总成绩。
函数接口定义:
double sumScore(struct student stu);
其中 stu是用户传入的参数。函数须返回学生的总成绩。
裁判测试程序样例:
#include <stdio.h>
struct student{int sid;char name[20];double math; //此数据成员表示数学程成绩double english; //此数据成员表示英语课程成绩double program; //此数据成员表示编程课程成绩
};
double sum(struct student st);
int main(){struct student st;scanf("%d%s%lf%lf%lf",&st.sid, st.name, &st.math, &st.english, &st.program);printf("%.2f\n",sum(st));return 0;
}/* 请在这里填写答案 */
输入样例:
1000 xiaopeng 90 90 90
输出样例:
270.00
解答过程
void sublistMaxMin(int* from, int* to, int* max, int* min) {*max = *from;*min = *from;for (int* ptr = from + 1; ptr <= to; ptr++) {if (*ptr > *max) {*max = *ptr;}if (*ptr < *min) {*min = *ptr;}}
}