Write a function, called calcAvgTemp, that accepts TWO (2) arguments in its parameter: a floating-point array, and a value representing the size for the floating-point array. Your solution must calculate the average of the values found in the array, and then return the result as a floating-point value.
#include <iostream>
using namespace std;
float calcAvgTemp(float arr[],int size){
float sum=0;
for(int i=0;i<size;i++){
sum=sum+arr[i];
}
float average=sum/size;
return average;
}
int main()
{
float arr2[10]={20.7,30.4,40.2,13.3,45.9,34.7,56.6,78.3,54.4,23.6};
cout<<"\nAverage: "<<calcAvgTemp(arr2,10);
return 0;
}
Comments
Leave a comment