C program to find out the sum of given G.P

source code


#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);
    getch();
    return 0;
}

Comments

Popular posts from this blog

8086 STRING MANIPULATION –FIND AND REPLACE A WORD

Animated Circles In C++

C program to find out the sum of series 1 + 2 + …. + n.