C language > Beginner questions
divisions
(1/1)
Marten:
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:
TimoVJL:
--- Code: ---
#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;
}
--- End code ---
cane:
Either:
--- Code: ---
float a=4.0/8.0;
printf("%f",a);
--- End code ---
--- Code: ---
float a=(float)4/8;
printf("%f",a);
--- End code ---
Marten:
Thanx !!!
Navigation
[0] Message Index
Go to full version