In the function returnAvg I need the code to return an array, but it only returns the first element I'm not to familiar with pointer. ar[0] is averaged completely but ar[1] is always 0 why is that happening?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double returnAvg(int allTest[2][2],int students,int test);
int main ()
{
int students = 2, test = 2, i,j;
int allTest[students][test];
double ar[students];
for(i = 0; i < students; i++){
for(j = 0; j < test; j++){
printf("Student [%d] test [%d] score was> ", i + 1, j + 1);
scanf("%d", &allTest[i][j]);
}
}
*ar = returnAvg(allTest, students, test);
for(i = 0;i<students;i++){
printf("\nthe average score of student[%d] is : %.2lf\n",i+1, ar[i]);
}
return 0;
}
double returnAvg(int allTest[2][2],int students,int test){
int i,j;
double avg[students];
for(i=0;i<students;i++){
int sum = 0;
for(j=0;j<test;j++){
sum += (allTest[i][j]);
}
avg[i] = (float)sum/test;
}
return *avg;
}