Below is a geometric progression calculator written in C.

It prompts the user to enter three numbers. The first number is the number you want the geometric progression to start with.

The second number is the multiplier, the number you want each successive number to increment by.

The third number is the number of integers you want in you progression.

The program should display the series and then present the sum.

If I have goofed on the terminology or the mathematics, please let me know, but I think it's OK.


#include <stdio.h>
#include <math.h>

main()
{
        int a, r, n, x, foo, sum = 0;

        printf("\nPlease enter three numbers");
        printf(" for your Geometric Progression Series.\n");

        printf("\nThe first number should be the number");
        printf(" you want to start with:\n");
        scanf("%d", &a);

        printf("\nThe second number should be what you want");
        printf(" the series to increment by:\n");
        scanf("%d", &r);

        printf("\nThe third number should be the amount of numbers");
        printf(" you want in the series.\n");
        scanf("%d", &n);

        for (x = 1; x <= n; x++)
        {
                foo = (x - 1);
                int terms = (a * (pow(r, foo)));
                printf("Term %d of the series is %d.\n", x, terms);
        }

        sum = a * ((pow(r, n) - 1) / (r - 1));

        printf("\nTheir sum is %d.\n", sum);

        return 0;
}