奇怪的算术 [英] Weird arithmetic
问题描述
嗨新闻组,
我是C的新手并且想知道以下代码:
#include< stdio.h>
int main(无效)
{
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);
返回0;
}
编译为GCC-3.4.3 on一个Linux盒子(Fedora Core 3 x86)输出
看起来像这样:
$ gcc -Wall -pedantic -std = c99 test.c -o测试
$ ./test
10045.000000 = 10045
20045.000000 = 20044
20045.000000 = 20045
怎么会这样?
提前致谢!
- Pascal
gcc -Wall -pedantic -std = c99 test.c -o test
./ test
10045.000000 = 10045
20045.000000 = 20044
20045.000000 = 20045
怎么会这样?
提前致谢!
- Pascal
" Pascal Gallois < pg@nowhere.net>在消息中写道
news:pa **************************** @ nowhere.net ... < blockquote class =post_quotes>嗨新闻组,
我是C的新手并且想知道以下代码:
#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);
返回0;
}
在Linux机器上用GCC-3.4.3编译(Fedora Core 3 x86)输出
看起来像这样:
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
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
"Pascal Gallois" <pg@nowhere.net> wrote in message
news:pa****************************@nowhere.net...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:
这篇关于奇怪的算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!