P
Pascal Gallois
Hi newsgroup,
I am new to C and wonder about the following code:
#include <stdio.h>
int main(void)
{
double m = 100.45;
double n = 200.45;
double o = 200.45;
int i = m * 100;
int j = n * 100;
o = n * 100;
int k = o;
printf("%lf = %i\n"
"%lf = %i\n"
"%lf = %i\n", m * 100, i, n * 100, j, o, k);
return 0;
}
Compiled with GCC-3.4.3 on a Linux box (Fedora Core 3 x86) the output
looks like this:
$ gcc -Wall -pedantic -std=c99 test.c -o test
$ ./test
10045.000000 = 10045
20045.000000 = 20044
20045.000000 = 20045
How could this be?
Thanks in advance!
- Pascal
I am new to C and wonder about the following code:
#include <stdio.h>
int main(void)
{
double m = 100.45;
double n = 200.45;
double o = 200.45;
int i = m * 100;
int j = n * 100;
o = n * 100;
int k = o;
printf("%lf = %i\n"
"%lf = %i\n"
"%lf = %i\n", m * 100, i, n * 100, j, o, k);
return 0;
}
Compiled with GCC-3.4.3 on a Linux box (Fedora Core 3 x86) the output
looks like this:
$ gcc -Wall -pedantic -std=c99 test.c -o test
$ ./test
10045.000000 = 10045
20045.000000 = 20044
20045.000000 = 20045
How could this be?
Thanks in advance!
- Pascal