Find the Sum of the Convergent Series...

 Find the Sum of the Convergent Series:

              2 + 0.5 + 0.125 + 0.3125


CODE in C:


#include<stdio.h>
float sum(float a, float r, float n) {
    float sum = 0;
    int i;
    for(i=0;i<n;i++) {
        sum = sum + a;
        a =a * r;
    }
    return sum;
}

int main() {
    float answer = sum(2,0.25,4);
    printf("Sum= %0.2f",answer);
    return 0;
}


OUTPUT:






Comments