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;
}
main()is not one of the signatures formain. Minumum isint main(void). Try that. Can you post the errors that you did see? undefinded function maybe? And what is this:int i,fact();? (my compiler generates warning:warning: function declaration isn't a prototype.termgoes from0.0037400.021478and then keeps getting larger untilinf.x,termnever gets small enough to leave the loop, resulting in an infinite loop. determine the valid ranges ofxthat your code should accept, then place a range limitation statement in to prevent running anything out of that range. By the way, your code does run on my Code::Blocks using MinGW (`gcc``)