Because the code is dividing an integer by another integer.
Used a literal number that is an integer value. When you consider only integers, the division of 1 by 3 gives the same number. After the calculation results in zero, it is converted to float
by the automatic casting rule. But note that this casting only occurs with the result as a whole and not on each operand individually.
#include <stdio.h>
int main() {
printf("o valor do numero e': %4.2f", 1.0f/3.0f);
}
See running on ideone . And no Coding Ground . Also I put GitHub for future reference .
Using the numeric literal for the floating-point type (1.0f for example), the division occurs correctly.