題干
請編寫一個函數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;}}
}