I made a program which accepts input for 30 users (About their age) and then the array was supposed to be an input in a custom function made by me (avg_age) However the average printed on screen is 0.0000 (for 30 non-zero values) That is why I think it does not return anything.
#include <stdio.h>
float avg_age(int age[]);
main()
{
int i=0,age[30]={0},intemp;
do{
printf("Input age for 30 users: ");
scanf("%d",&intemp);
if(intemp>0 && intemp<100)
intemp=age[i];
else i--;
i++;
}while(i<30 || intemp<0 || intemp>100);
printf("\nAverage age of 30 users: %f\n",avg_age(age));
float avg_age(int age[]){
int i,avg=0;
for(i=0;i<30;i++)
avg+=age[i];
avg=(float)avg/30;
return avg;
}
}
intemp=age[i];
=>age[i]=intemp;
. You're not storing the ages in the array.