+ 5
How the output is 0?[solved]
17 Answers
+ 7
because 1 and 2 are int, and 1/more than 1 result to 0...
+ 4
Because in C++ and C (and, maybe, in some other programming languages using separate data types for integers and floating-point/decimals, excluding Python) operators with integers return integers: 1 / 2 * 10 * 10 = 0 * 10 * 10 = 0 * 10 = 0.
+ 4
try to put 1.0/2 to compute floating division, you'll get 50...
+ 4
Or `(float) 1 / 2 * b * h` (the same as visph has written, but giving the converting 1 to float work to the compiler).
+ 4
dividing int by int result to int
dividing float by int or float give float
+ 4
Atul, (continuing my first answer here); if one of the operands is float/double/long double (in C++ and C), the answer will be of this type. It was made for both precision and efficiency.
+ 3
๐โฟแตหขแตแตหก๐ฅ๐๐ง๐จ๐ค๐ฃ operator precedence of * and / are same, so left to right rule apply ^^
+ 2
So what should be done to make it 50?
+ 2
Why after converting it into double it is showing the correct answer?
+ 2
Ok thank you
+ 2
๐โฟแตหขแตแตหก๐ฅ๐๐ง๐จ๐ค๐ฃ expected output is 50, not 0.005...
first is computed 1/2 wich result to 0 as both numerator and divisor are int (but 0.5 expected)
then 0.5*10 = 5
then 5*10 = 50
+ 1
Variable 'a' is declare as 'int' type so it having a capability to store the integer value.
1/2*10*10 ==0.005
But it contain only integer part of (0.005) that is zero(0).....โ๏ธ
+ 1
visph According to operator precedence * first execute then / will be execute.
+ 1
Amit Brar rgb is stand for red,green,blue color.it's value very from 0 to 255.
Where rgb(0,0,0)-->black
And rgb(255,255,255)-->white
+ 1
๐โฟแตหขแตแตหก๐ฅ๐๐ง๐จ๐ค๐ฃ you could now remove the unrelated answer about rgb colors ;)
0
z=2*10*10
a=int(1/200)=int(0.05)=0
https://code.sololearn.com/cyiqR1014jXG/?ref=app