**The Program in C that uses a function that can compute sum of any geometric serie**s** is given below:**

```
#include <stdio.h>
double geometric_series_sum(double a, double r, int n) {
// Function to calculate the sum of a geometric series
return a * (1 - pow(r, n)) / (1 - r);
}
int main() {
double a, r;
int n;
printf("Enter the first term of the series: ");
scanf("%lf", &a);
printf("Enter the common ratio of the series: ");
scanf("%lf", &r);
printf("Enter the number of terms in the series: ");
scanf("%d", &n);
printf("The sum of the geometric series is: %lf", geometric_series_sum(a, r, n));
return 0;
}
```

## Output:

Enter the first term of the series: 4

Enter the common ratio of the series: 51

Enter the number of terms in the series: 6

The sum of the geometric series is: 1407703024.000000

## Pro-Tips**💡**

This program uses the same formula as before to calculate the sum of the geometric series but in this version, I have removed the unnecessary variable `double sum`

and the return statement is added in the function itself.

Also, I have removed the declaration of `sum`

inside the `main`

function and the function is called inside the `printf`

statement.

This will make the code more concise and easier to read.

**Learn C-Sharp ↗**

C-sharp covers every topic to learn about C-Sharp thoroughly.

**Learn C Programming ↗**

C-Programming covers every topic to learn about C-Sharp thoroughly.

**Learn C++ Programming↗**

**Learn C++ Programming↗**

C++ covers every topic to learn about C-Sharp thoroughly.