Pelles C forum
C language => Beginner questions => Topic started by: Marten on December 30, 2006, 07:43:20 PM
-
How can i divide 4/8 in c or 3/2 or things like that cause i always get 0.0000 when i use the following code:
float a=4/8;
printf("%f",a);
!?!?!? :cry:
-
#include <stdio.h>
#include <math.h>
int main(int argc,char **argv)
{
float a;
a=4/8;
printf("%f\n",a); //0.000000
a=4.0/8;
printf("%f\n",a); //0.500000
a=(float)4/8;
printf("%f\n",a); //0.500000
return 0;
}
-
Either:
float a=4.0/8.0;
printf("%f",a);
float a=(float)4/8;
printf("%f",a);
-
Thanx !!!