Computer Science, asked by poojapandit979737, 4 days ago

calculate the average of five number using function with return type and with argument

Answers

Answered by mayursaxena79
0

Answer:#include <stdio.h>

float array_average(float a[] , int n); //function declaration

float array_average(float a[] , int n){ //function definition

 

int i;

 

float sum = 0; //initialising the variables

 

for(i = 0 ; i < n ; i++) //adding all the elements in the array

sum+=a[i];

 

return sum/n; //returning the average of array

 

 

}

int main()

{

int n = 9;

 

float a[9] = {1,2,3,4,5,6,7,8,9}; //declaring one dimensional array

 

 

float result = array_average(a,n); //calling function array_average

 

printf("The average of the array is %.2f",result); //displaying the result

 

}

Similar questions