/* Write a program to calculate the sum in Geometric Progression */
#include <stdio.h>
#include <math.h>
int main() {
float a, r, i, tn;
int n;
float sum = 0;
printf("Enter the first number of the GP: ");
scanf("%f", &a);
printf("Enter the total numbers in the GP: ");
scanf("%d", &n);
printf("Enter the common ratio of GP: ");
scanf("%f", &r);
sum = (a*(1 - pow(r, n+1))) / (1-r);
tn = a * (1 - pow(r, n-1));
printf("tn term of GP: %f", tn);
printf("\nSum of the GP: %f", sum);
getch();
return 0;
}
Tuesday, February 10, 2015
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment