/* gpsum.cpp -- the program 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 your progression.
The program should display the series
and then present the sum. */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a, r, n, x, foo;
long 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);
unsigned long terms = (a * (pow(r, foo)));
printf("Term %d of the series is %u.\n",
x, terms);
}
sum = a * ((pow(r, n) - 1) / (r - 1));
printf("\nTheir sum is %u.\n", sum);
system("PAUSE");
return 0;
}
:: Top ::