main()
{
int num=4478;
float num2;
num2=num/100;
printf("%.2f ",num2);
}
C language- why is it not printing a float, and tell me how to fix it?
main()
{
int num=4478;
float num2;
num2=num/100;
printf("%4.2f ",(float)num2);
}
try this, this one is type conversion in stmt num2=num/100 you are formulating the integer value to float variable.
Reply:num2=(float)num/100; change this,,,,then u wil get the result properly
Reply:Any one of the numbers should be a floating point number to get the floating point result
You can change your program like this
main(){
int num=4478;
float num2=num/100.0;
printf("%.2f",num2);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment