find sum of infinite series.Why does it issue a zero amount?

Viewed 75

You need to find the sums of an infinite series with a given accuracy.(the picture with the task is given as a link) the program constantly counts the zero amount. I don't understand what my mistake is

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
    int i;
    int n =1;
    double E,x,q;
    double sum = 0;

    scanf ("%f",&E) ;
    scanf ("%f",&x) ;

    q=pow(x,3)/6;

    while(fabs(q)>=E){

        if (n/2==0) {
            sum=sum+q;
        }
        else {
            sum=sum-q;
        }
        q=(q*pow(x,2))/(n+3);
        n=n+1;
    }
    printf("%f",sum);
    return 0;
}
1 Answers

It will never going to enter to that if statement. You are letting n=1 and it will be always 1, and u are doing n=n+1 in the else.

Related