Advertisement
hiker43

GeoMean

Sep 6th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double GeoSredina(double *ptr, int size);
  7.  
  8. int main()
  9. {
  10.     int numbers;
  11.     cout<<"Enter how many numbers: ";
  12.     cin>>numbers;
  13.  
  14.     double *ptr= new double[numbers];
  15.  
  16.     for (int i=0; i < numbers; i++)
  17.     {
  18.         cout<<"Enter number: ";
  19.         cin>>*(ptr+i);
  20.     }
  21.     double aaa= GeoSredina(ptr, numbers);
  22.     cout<<"Geometric mean of the elements is: "<<aaa;
  23.     delete[] ptr;
  24. }
  25.  
  26. double GeoSredina(double *arr, int size)
  27. {
  28.     double proizvod=1;
  29.     for( int i=0; i < size; i++)
  30.     {
  31.         proizvod*=*(arr + i);
  32.  
  33.     }
  34.     proizvod=pow(proizvod, 1.0/size);
  35.     return proizvod;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement