What's the result?

Philippines
November 20, 2008 2:50am CST
Hello, I got a simple question, which one below gives the 50.0 result? float constNum = 100; float a = 0 + (50 / 100) * constNum; float b = 1 * 50 * constNum / 100;
3 responses
@mr_mlk (364)
22 Nov 08
float a= 0 + (50/ 100)* constNum (50/ 100) = 0.5, but as 50 and 100 are ints not floats this is truncated to "0". 0 + 0 * constNum = 0 + (0 * constNum) = 0 + (0 * 100) = 0 + 0 = 0 float b= 1* 50* constNum/ 100 1* 50* constNum/ 100 = (1* 50)* constNum/ 100 = 50 * constNum/ 100 50 * constNum/ 100 = (50 * constNum) / 100 = 5000 / 100 5000 / 100 = 50
1 person likes this
• Philippines
23 Nov 08
wow nice! good job ;)
• India
20 Nov 08
I think the seccond one will give the right answer : constNum/100=1 1*50*1=50 At one shot I feel seccond one is correct.
1 person likes this
• Philippines
20 Nov 08
hi Manojknair. tnx for your reply. can you explain to me why? the first one would probably give you the same answer, isn't it? a = 0 + (50/ 100)* 100 a = 0 + (0.5)* 100 a = 0 + 50.0 a = 50.0
• India
8 Jan 09
the result is first evaluate the parnthes after that multiplication ie 0.5*100 is 50 second one is also 50