this question has answer here:
- c program convert fahrenheit celsius 8 answers
i trying implement below formula on c
here code:
int function(int x){ return pow(10, (((x-1)/(253/3))-1)); } int main(void){ int z = function(252); printf("z: %d\n",z); return 0; }
it outputs 10. calculator outputs 94.6.
could explain me doing wrong?
note in line
(((x-1)/(253/3))-1))
you dividing integer value x - 1
integer value 253 / 3
. truncate value int
, meaning you'll raising integer power integer power.
to fix this, try changing expression to
(((x-1)/(253.0 / 3.0))-1))
this use double
s in expression, giving value want.
hope helps!
Comments
Post a Comment