+ 1
Calculation Problem
I wrote a code and find a problem in calculation, so I want to know how C calculates it. When I calculate it by BODMASS method I got k = 3, but C shows k = 2, why? https://code.sololearn.com/c6cqUOp4e6y4/?ref=app
2 Answers
+ 1
ćļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć
j is 3 here.
I think this is happening because we're working with integers. 3/2 is calculated as 1. The part after the decimal point is ignored. If we change the line to
k = 2 * ((float) j / 2);
it should work out.
+ 1
ćļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć
š
It's the intention that matters. Your explanation was very detailed.