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
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.
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:-
You May Like This
1. C++ Program To Find Area And Circumference Of Circle
2. C++ Program To Print Ascii Value Of Character
3. C++ Program To Find Area Of Triangle
4. C++ Program to Convert a person's name in Abbreviated
5. C++ Program For Calculate A Simple Interest
6. C++ Program To Find Greater No. Among given Three Number
7. C++ Program For Find The Gross Salary Of An Employee
8. C++ Program For Calculate Percentage Of 5 Subjects
9. C++ Program For Converting Temperature Celsius Into Fahrenheit
10. C++ Program To Display Size Of Different Datatype
0 Comments: