**Sum of GP series in c programming language**

#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;

}

**Sample output:**

Enter the first number of
the G.P. series: 1

Enter the total numbers in
the G.P. series: 5

Enter the common ratio of
G.P. series: 2

tn term of G.P. : 16.000000

Sum of the G.P. : 63.000000

**Definition of geometric progression (G.P.):**

A series of numbers in which
ratio of any two consecutive numbers is always a same number that is constant.
This constant is called as common ratio.

**Example of G.P. series:**

2 4 8 16 32 64

Here common difference is 2
since ratio any two consecutive numbers for example 32 / 16 or 64/32 is 2.

**Sum of G.P. series:**

S

_{n}=a(1–r^{n+1})/(1-r)**T**

_{n}term of G.P. series:
T

_{n}= ar^{n-1 }**Sum of infinite G.P. series:**

S

_{n}= a/(1-r) if 1 > r
= a/(r-1) if r > 1

6. Write a c program to find out the sum of given H.P.

## 6 comments:

correct it tn=a*pow(r,n-1) , not tn=a*(1-pow(r,n-1))

u r r8 Manna.

correct balaram bro

help full

thanks.

code to print 3,9,27,81,243,729..............

#include

#include

int main()

{

int a,r,n,i;

float tn;

printf("enter the first element of the series:");

scanf("%d",&a);

printf("enter the common ratio:");

scanf("%d",&r);

printf("enter the number of elements:");

scanf("%d",&n);

for(i=1;i<=n;i++)

{

tn=a*(pow(r,i-1));

printf("%.0f,",tn);

}

return 0;

}

Post a Comment