Tuesday, February 10, 2015

Sum of Geometric Progression

/* 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; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar