# Thread: sum of series using loops

1. ## sum of series using loops

I am trying to use the sum ∑ from i=0 to N of x^(2i+1)/(2i+1)! which is the sum of the series of sinh. now i am able to get the top part of the series but the buttom part i am having issues

basically this is the part that i have issues with :

Code:
```for(i = 1;i <= N+1; i = i + 2){

for(j=1 ; j <= i; j++)
{
f= f * j;
}

sum = sum + pow(x,i)/f;

}
return sum;

}```

mainly the 2nd "for".

and yes I know that c can compute sinh however my homework says that i have to do this so here we are.

Code:
```#include <stdio.h>#include <stdlib.h>
#include <math.h>

#define TRUE 1
#define FALSE 0

void getInput(double *N, double *x);
double sinHyper(double N , double x);

int main()
{
double sum;
double N;
double x;
char ans;
int flag;

do
{
flag = TRUE;

getInput(&N,&x);
sum = sinHyper(N,x);
printf("\nsum : %g\n\n\n", sum);

printf("Do you wish to quit (y/n)? ");
fflush(stdin);
scanf("%c",&ans);

if( ans != 'n')
{
printf("Program terminated \n");
flag = FALSE;
}
} while(flag == TRUE);

}

void getInput(double *N, double *x)
{
int flag;// Declaration of variable

double N1, x1;
do
{
flag = TRUE;
printf("Please enter the number of terms N : ");
scanf("%lf",&N1);
printf("Please enter the value x : ");
scanf("%lf",&x1);

if( N1 < 0.0)
{
printf("the value of N must be greater than zero.\n");
flag = FALSE;
}
*N = N1;
*x = x1;
} while(flag == FALSE);// Get input from user

}

double sinHyper(double N , double x)
{
double i , j;
double sum = 0;
double f = 1;
double k = 1;

for(i = 1;i <= N+1; i = i + 2)
{

for(j=1 ; j <= i; j++)
{
f= f * j;
}

sum = sum + pow(x,i)/f;

}
return sum;

}``` 2. never mind i figured it out dont waste ur time on this 3. You could edit your final post with how you worked it out, just in case anybody else have the same issue. 4. basically this is the part i fixed
Code:
```

double sinHyper(double N , double x)

{
double i ;
double sum = x;
double t = x;

for(i = 1;i <= N-1; i++)

t= (t*x*x)/((2*i+1)*2*i)
sum = sum + t

}
return sum;

}

``` 5. Just a side point.

Code:
`sum = sum + t`
You can write the more concise:

Code:
`sum += t;` Popular pages Recent additions basically, issues, part, series, sum 