Mail Archives: djgpp/1997/07/19/22:54:23
and I got an the folowing (2), do you know why?
Yes - the code you are not showing us has bugs in it ;)
> float a=0;
> float b=0;
> float c=0;
> a=375;
> b=150;
> c=a/b;
> (2)
> I got: c=2
If you enter just the code you have entered here gcc will optimize out all of
the variables and division, and just push an immediate value of 2.5 on
the stack (assuming you call printf or something).
> This return is 'cause '/' returns only an integer. (I think so).
Nope. Not unless you are using integer values or are coercing the value with
(int) a/b).
try this
#include <stdio.h>
int main(void) {
float a,b,c;
printf("Enter a float\n");
scanf("%f",&a);
printf(Enter another float\n");
scanf("%f",&b);
c = a/b;
printf("float 1/float 2 = %f\n",c);
return 0;
}
Andrew
- Raw text -