Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I will store float data in an array and we will assume a maximum of 10 values Wr

ID: 3629585 • Letter: I

Question

I will store float data in an array and we will assume a maximum of 10 values
Write a function which must accept two arguments, the data array and how many data
values there are in it to be averaged. The function must return a float which is the average of the data provided. Note if the user entered 3 values then we must average over only the first 3 array elements not all 10.
In the main code first create a float array to hold 10 values.
Then repeatedly ask the user how many floats they wish to enter until they enter a
number in the range 1-10.
Then ask them to enter that many data values and fill (part of) the array.
Call the averaging function and print the result to the screen.

Thanks a lot !

Explanation / Answer

please rate -thanks

#include <stdio.h>
#include <conio.h>
float getAverage(float[],int);
int main()
{float a[10],average;
int i,n;
printf("How many numbers do you have? ");
scanf("%d",&n);
while(n<1||n>10)
    {printf("must be between 1 and 10 ");
     printf("How many numbers do you have? ");
     scanf("%d",&n);
     }
printf("Enter your %d numbers ",n);
for(i=0;i<n;i++)
   {printf("Enter number %d: ",i);
   scanf("%f",&a[i]);
}
average=getAverage(a,n);
printf("The average is %.2f ",average);
getch();
return 0;
}
float getAverage(float a[],int n)
{int i;
float sum=0;
for(i=0;i<n;i++)
    sum+=a[i];
return sum/n;
}