Hello everybody. My first post here so please be gentle.
I have a problem I don't know how to weed out. I have a simple programme calculating some sequence and I literally have no variables declared as integer. However, when I call a function (again, declarations "double" left and right), it returns as "int".
Here are the relevant parts:
Code:
int main()
{ double i, add, x, enax;
....
add = (double) pow((-1), (i)) * pow(x, i) / fact(i);
....
}
fact(double a)
{
double j, f;
for (j=1.0, f=1.0; (j <= a); j++)
{ f *= j; }
return f;
}
The even more rediculous thing is, while factorials are calculated inside the function, "f" is "double" (I checked by putting a printf command). however, the moment it is returned to main(), fact(i) has become "int".
When I get stubborn, I can't even compile it because, when trying to print out the mid-results, I get:
Code:
enax.c:19:7: warning: format ‘%g’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Wformat=]
*/ printf("potencija %g, faktorijel %g \n", pow(x, i), fact(i));
This "third argument" is, naturally, fact(i)
When I take out this control mid-step, I get an error because the integer factorial overflows at i=14 and I want it much, much higher.
Any ideas?