Calculation Problem | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ 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
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ šŸ˜Š It's the intention that matters. Your explanation was very detailed.
1st Oct 2018, 4:52 PM
Kishalaya Saha
Kishalaya Saha - avatar