Question:Sum of infinite GP series in c programming language 

Answer 
#include<stdio.h>

int main(){

    float a,r;
    float sum=0;

    printf("Enter the first number of the G.P. series: ");
    scanf("%f",&a);

    printf("Enter the common ratio of G.P. series: ");
    scanf("%f",&r);

    if(1 > r)
         sum = a/(1-r);
    else
         sum = a/(r-1);

    printf("\nSum of the infinite G.P. series: %f",sum);

    return 0;
}
Sample output: Enter the first number of the G.P. series: 1 Enter the common ratio of G.P. series: .5 Sum of the infinite G.P. series: 2.000000 Enter the first number of the G.P. series: 5 Enter the common ratio of G.P. series: 2 Sum of the infinite G.P. series: 5.000000 

+ Report
Total Preview: 646
Sum of infinite GP series in c programming language
Copyright © 2024. Powered by Intellect Software Ltd