Sunday, 13 March 2016

Write A C++ Program To Average Of Array In Function Of Using Pointer

#include
using namespace std;
// function declaration:
double getAverage(int *arr, int size);

int main ()
{

   int balance[50],i,n;
   double avg;
cout<<"Enter The Size Of Array\n";
cin>>n;
cout<<"\nEnter The "< for(i=0;i cin>>balance[i];

    avg = getAverage( balance,n) ;
    cout << "Average value is: " << avg << endl;
 
   return 0;
}

double getAverage(int *arr, int size)
{
  int    i, sum = 0;    
  double avg;        

  for (i = 0; i < size; ++i)
  {
    sum += arr[i];
   }

  avg = double(sum) / size;

  return avg;
}

Output:-



No comments:
Write comments

Recommended Posts × +