67 107
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #68793 in C for M ATIF HAROON

Question #68793
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
Expert's answer
#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;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions