0
What's the difference in both?
float area; float base = 5; float height = 10; area = (1/2)*base*height; OUTPUT: area = 0 area = (0.5)*base*height; OUTPUT: area = 25 Why so?
2 ответов
+ 7
1/2 is integer division which returns 0.
+ 1
to force float division add a float literal at any side (or both) of the division operator:
area = (1.0/2.0)*base*height;