programming-examples/c/Series_Programs/Write a c program to find out the sum of given G.P.c

18 lines
539 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
#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 G.P. series: ");
scanf("%f",&a);
printf("Enter the total numbers in the G.P. series: ");
scanf("%d",&n);
printf("Enter the common ratio of G.P. series: ");
scanf("%f",&r);
sum = (a*(1 - pow(r,n+1)))/(1-r);
tn = a * (1 -pow(r,n-1));
printf("tn term of G.P.: %f",tn);
printf("\nSum of the G.P.: %f",sum);
return 0;
}