In the code, The return is Value of n[0] : 12 My question is, where the heck are they getting the numbers 12, 234, 12.43, and 43.43 from?? It never declares what j is, nor does it ever ask for any values from user, so where are those random numbers coming from?
#include <stdio.h>
float average(float a[], int size)
{
int i;
float avg, sum=0;
for(i=0;i<size;i++)
{
sum+= a[i];
}
avg = sum/size;
return avg;
}
int main()
{
int size,j;
printf("Enter the size of array");
scanf("%d", &size);
float b, n[size];
for(j=0; j<size; j++)
{
printf("Value of n[%d] : ", j);
scanf("%f", &n[j]);
}
b = average(n, size);
printf("Average of numbers=%.2f\n",b);
return 0;
}
Value of n[1] : 234
Value of n[2] : 12.43
Value of n[3] : 43.43
Average of numbers=75.46
I ran the code and it is working as expected. It is asking for the numbers and then printing the average. https://ideone.com/BqEeY6