# C CODE HELP

I am creating a code that will me to input the name, ages, and state of residence of my relatives. I also have to calculate the average age of my family. I can get all parts of the code to work properly except calculating the average age of my family. I can’t seem to figure out how to calculate the average of less than 50 family members. Can someone please help.

Hello, let us store ages of your relatives in an array a[].

Let N=50 (total number of your relatives)

double Avg_Age=0.0000000;

So after this you can do something like :

```for(int i = 0; i < N; ++i) {
Avg_Age += (double)a[i];
}

Avg_Age = (double) Avg_Age / N;```

Type casting in important.I hope it helps.

Best,

Chaitanya.

First read salary in array and then calculate the average. Lets say your family have 40 members. The code will be something like this.

int n=40,i;
float salary[40],avg=0.0;

for(i=0;i<40;++i)
{
scanf("%f",&salary[i]);
avg=avg+salary[i];
}
avg=avg/40;

Just add this code in your existing program. Let me know if you have any other doubts.

Happy Coding!!