Write two different functions. One calculates the average for each student and stores it in
an array. The second function calculates the average for each course and stores it in an
array
1
Expert's answer
2017-06-12T08:54:06-0400
#include <stdio.h> #include <stdlib.h> #define N 15 //amount of students #define K 5 //amount of subjects #define C 5 //amount of courses typedef struct subjects{ char subj[20]; double mark; }SUBJECTS;
typedef struct student{ char name[20]; int course; SUBJECTS mas[K]; }STUDENT;
int main() { STUDENT Arr1[N]; double Arr2[N], Arr3[C]; Average(Arr1, Arr2); AverageCourse(Arr1, Arr3); return 0; } /*average for each student*/ void Average(STUDENT * ArrOfStudents, double * ArrOfAverageMarks) { int i, j; double sum; for(i=0;i<N;i++){ sum=0; for(j=0;j<K;j++) sum+=ArrOfStudents[i].mas[j].mark; sum=sum/j; ArrOfAverageMarks[i]=sum; } } /*average for each course*/ void AverageCourse(STUDENT * ArrOfStudents, double * ArrOfAverageCourse) { int i, j, k, count; double sum; for(i=1;i<=C;i++){ sum=0; for(j=0, count=0;j<N;j++) if(ArrOfStudents[j].course==i){ count++; for(k=0;k<K;k++) sum+=ArrOfStudents[j].mas[k].mark; } sum=sum/count; ArrOfAverageCourse[i-1]=sum; } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment