C++ Program To Find Average of An Array Elements Using Pointers

Problem:- C++ Program to Calculate the Sum of the Array Elements using Pointer or C++ Program to Access Elements of an Array Using Pointer or c++ program to find sum of array elements using pointers or how to pass array to function in c++ by reference or Passing By Reference With Arrays C++ or passing array by reference c++ example or passing an array by reference c++ or c++ program to find sum of array elements using pointers or array of pointers c++ example or how to make a pointer to an array c++ or c program to display array elements using pointers or find average using pointers in c or c program to find the sum of n numbers using pointers or c++ program to display array elements using pointers or c++ pointer to array of pointers or

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- In this problem we are passing the value of an array using reference(passing address of the variable) so for this problem we create a function after that we took an array value by user after taking an array value we pass the address of an array to function(we pass the first index address and size of an array) and put the some condition statements in function that help us to calculate the average of an array. After calculating the average of an array we return the average to function and int main function we print the value of an array calculated after average.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- If this post is beneficial for you and you want Updates for New post then please like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.

Solution:-

#include<bits/stdc++.h>
using namespace std;

// function declaration:
double Average(int *arr, int size);

int main ()
{

int i, n;
double avg;
cout<<"Enter The Size Of Array\n";
cin>>n;
int average[n];
cout<<"\nEnter The Array Elements\n";
for(i=0; i<n; i++)
{
cin>>average[i];
}

cout << "\n\nAverage Value of An Array Is: " << Average(average , n)<< endl;

return 0;
}

double Average(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:-