This is because of implicit conversion. The variables b, c, d
are of float
type. But the /
operator sees two integers it has to divide and hence returns an integer in the result which gets implicitly converted to a float
by the addition of a decimal point. If you want float divisions, try making the two operands to the /
floats. Like follows.
#include <stdio.h>
int main() {
int a;
float b, c, d;
a = 750;
b = a / 350.0f;
c = 750;
d = c / 350;
printf("%.2f %.2f", b, d);
// output: 2.14 2.14
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…