Sunday, 26 February 2012

Average of numbers using array


# include <iostream>
using namespace std;
void readArray(int arr[], const int size);
double average(int arr[], const int size);
int main(){
const int size = 10;
int arr[size];
readArray(arr,size);
cout<<"average of the Entered array : "<<average(arr,size)<<endl;
return 0;

}
void readArray(int arr[], const int size)
{
for(int i = 0; i<size; i++)
{
cout<<"enter element : "<<endl;
cin>>arr[i];
}

return;
}

double average(int arr[], const int size)
{
int sum = 0;
for(int i = 0; i<size; i++)
sum += arr[i];
return static_cast<double> (sum/size);

}

No comments:

Post a Comment