Just to be clear the problem in
Is that 1 and 3 are both integer constants so the calculation is done in integer arithmetic which drops all decimal places therefore 1/3 = 0.
This is easy to fix by forcing 1 or both of the constants to be floating point constants by adding the decimal, the sum will then be calculated using floating point arithmetic and you will get the expected result
(Note I added a . the decimal point). Of course by default floating point constants have type double and you are using float. Normally it is best to keep your types the same to prevent conversion although strictly the compiler does all floating point calculations as double and the converts down to float anyway.
Normally we would also say don't bother using float use double unless you have a particularly low memory platform. but if you did want to specify constants with type float you would do it like this
-
float num=1.F/3.F, sum=0;
-