Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double GeoSredina(double *ptr, int size);
- int main()
- {
- int numbers;
- cout<<"Enter how many numbers: ";
- cin>>numbers;
- double *ptr= new double[numbers];
- for (int i=0; i < numbers; i++)
- {
- cout<<"Enter number: ";
- cin>>*(ptr+i);
- }
- double aaa= GeoSredina(ptr, numbers);
- cout<<"Geometric mean of the elements is: "<<aaa;
- delete[] ptr;
- }
- double GeoSredina(double *arr, int size)
- {
- double proizvod=1;
- for( int i=0; i < size; i++)
- {
- proizvod*=*(arr + i);
- }
- proizvod=pow(proizvod, 1.0/size);
- return proizvod;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement