code:
#include<stdio.h>
main()
float i;
i=16.0/9;
printf("%d",i);
}
i m getting 0 as output instead of 1. why?
code:
#include<stdio.h>
main()
float i;
i=16.0/9;
printf("%d",i);
}
i m getting 0 as output instead of 1. why?
division as double, and that's not how you print a float (%d is a signed integer and %f is a float), See http://www.cplusplus.com/reference/c...io/printf.html
Code:#include <stdio.h> int main(void) { float i; i = 16.0f / 9.0f; printf("%f", i); return 0; }Originally Posted by iMalc
Last edited by zacs7; 06-20-2007 at 03:36 AM. Reason: Miss wording pointed out by vart
division was OK... it was even performed as double and then shortened to float...
printf format IS really a problem...
and also missing code tags
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler