Sunday, 13 March 2016

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:-

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


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



Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment