# C++ Program to Find the Sum of Geometric Progression Series

This C++ program calculates the sum of geometric progression. The program takes the first term, the common ratio and the number of terms as input. A function is called to calculate the sum of the progression and to print it.

Here is the source code of the C++ program calculates the sum of geometric progression. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

1. `/*`
2. ` * C++ Program to Calculate Sum of Geometric Progression`
3. ` */`
4. `#include <iostream>`
5. ` `
6. `void calSumGP(float a, float r, int n)`
7. `{`
8. `    float sum = 0, temp = a;`
9. ` `
10. `    for (int i = 1; i < n; i++)`
11. `    {`
12. `        sum = sum + temp;`
13. `        temp = temp * r;`
14. `    }`
15. `    std::cout << "Sum of geometric progression : "`
16. `              << sum << std::endl;`
17. `}`
18. ` `
19. `int main()`
20. `{`
21. `    int n;`
22. `    float a, r;`
23. ` `
24. `    std::cout << "Enter the value of a = ";`
25. `    std::cin  >> a;`
26. `    std::cout << "Enter the value of r = ";`
27. `    std::cin  >> r;`
28. `    std::cout << "Enter the value of n = ";`
29. `    std::cin  >> n;`
30. `    calSumGP(a, r, n);`
31. `}`

```\$ a.out
Enter the value of a = 1
Enter the value of r = 2
Enter the value of n = 10
Sum of geometric progression : 511```

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.