# Help with arrays

This is a discussion on Help with arrays within the C Programming forums, part of the General Programming Boards category; Hello I try to write this code it takes in 12 numbers from the user and puts it into an ...

1. ## Help with arrays

Hello I try to write this code it takes in 12 numbers from the user and puts it into an array then the array is passed on the another function then the average of those 12 numbers are taken. But I can'nt seem to get it working I will be very greatful if anyone can fix my code.

Code:
```#include <stdio.h>

#define size 12

double ave (int a[size]);

int main()
{
int a[size];
int i;

for(i=0; i<=12; i++)
{
printf("Please enter the 12 numbers needed: ");
scanf("%d",&i);
}

ave (&a[size]);

return 0;
}

double ave (int a[size])
{
double value;
int i;

for(a[i]=1; a[i]<13; i++)
{
value= i/12;
}

printf(" the average value is %d\n",i);

return 0;
}```

2. proper working code

Code:
```#include <stdio.h>
#define size 12

float ave(int []);

int main()
{
int a[size];
int i,ch;

printf("Please enter the 12 numbers needed: ");
for(i=0; i<12; i++)
scanf("%d",&a[i]);

printf("The average of the array is %f",ave(a));

while((ch=getchar())!='\n' && ch!=EOF);
getchar();
return 0;
}

float ave(int a[])
{
float total=0.0;
int i;

for(i=0;i<size;i++)
total+=a[i];

}

/*my output
Please enter the 12 numbers needed: 12
3
4
5
6
7
8
9
10
11
12
13
The average of the array is 8.333333```
ssharish2005