This is the code i wrote to find the term that is lower than 0.00005 in a series depends on the value of x entered. When i run the code with value x equal to 1 and 2 the code work fine, but when i enter number 3 or number that is more than 3, code block seems to have some error with the compiler. Does anyone know what can i do to fix this?
#include <math.h>
#include <stdio.h>
main()
{
double term=1.0,x;
int i,fact();
printf("Enter the value of x: ");
scanf("%lf",&x);
for(i=0;term>0.00001;i++){
term=fabs((pow(-1,i)*pow(x,2*i))/fact(2*i));
}
printf("The term become smaller than 0.00005 when term %d reached\n",i );
}
//method for calculating factorial
int fact(int num)
{
int fact=1;
for(int i=1;i<=num;++i){
fact*=i;
}
return fact;
}