+ 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

1st Oct 2018, 3:15 PM
Pritam Kumar Das
Pritam Kumar Das - avatar
2 Respostas
+ 1
「HAPPY TO HELP」 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.
1st Oct 2018, 4:30 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
「HAPPY TO HELP」 😊 It's the intention that matters. Your explanation was very detailed.
1st Oct 2018, 4:52 PM
Kishalaya Saha
Kishalaya Saha - avatar