- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find N Geometric Means between A and B using C++.

Suppose we have three integers A, B and N. We have to find N geometric means between A and B. If A = 2, B = 32, and N = 3, then the output will be 4, 8, 16

The task is simple we have to insert N number of elements in the geometric Progression where A and B are the first and last term of that sequence. Suppose G1, G2, …. Gn are n geometric means. So the sequence will be A, G1, G2, …. Gn, B. So B is the (N + 2)th term of the sequence. So we can use these formulae −

$$B=A*R^{N+1}$$

$$R^{N+1}=\frac{B}{A}$$

$$R=\lgroup \frac{B}{A}\rgroup^{\frac{1}{N+1}}$$

## Example

#include<iostream> #include<cmath> using namespace std; void showMeans(int A, int B, int N) { float R = (float)pow(float(B / A), 1.0 / (float)(N + 1)); for (int i = 1; i <= N; i++) cout << (A * pow(R, i)) <<" "; } int main() { int A = 3, B = 81, N = 2; showMeans(A, B, N); }

## Output

9 27

- Related Articles
- Find N Arithmetic Means between A and B using C++.
- Find Harmonic mean using Arithmetic mean and Geometric mean using C++.
- Program to find greater value between a^n and b^n in C++
- Find the resistance between A and B."\n
- Find a subset with greatest geometric mean in C++
- C Program for N-th term of Geometric Progression series
- If $n(A)=30, n(B) = 45, n(A cup B) = 65$ then find $n(A cap B)$, $n(A-B)$ and $n(B-A)$.
- Removing a Number from Array to make It Geometric Progression using C++
- Find the distance between the following pair of points:$(a + b, b + c)$ and $(a – b, c – b)$
- Find the missing number in Geometric Progression in C++
- Find value of a and b."\n
- Find the only repetitive element between 1 to n-1 using C++
- Find all triplets in a sorted array that forms Geometric Progression in C++
- Find mean of subarray means in a given array in C++
- What is the difference between K-Means and DBSCAN?

Advertisements