|
|
||||
|
|
This tip submitted by M.Kumaran on 2005-08-17 02:32:10. It has been viewed 32883 times.
Rating of 3.8167 with 180 votes logical error on divisionLook at the program
main()
{
float ans;
ans=5/10;
printf("%f",ans);
}
what is the output? The output is not like this: 0.50000 The output is 0.000000 because int/int = int so change the program to
main()
{
float ans;
ans=5/10.0;
printf("%f",ans);
}
the above programm is (int/float) so the output is now 0.500000 int/int = int int/float = float float/int = float float/float = float The above table can be summarized as: integer division takes place only when both elements are integers. More tips Add a tip! ----- |
|
||
|
|
||||