为什么最后输出的numOne跟实际差距这么大,而且有时候还会是负整数,是哪里错了?
#include <stdio.h>
int main()
{
double numOne = 2.5; //定义浮点型变量num并赋值为2.5
int numTwo = (int)numOne;
printf("numOne的整数部分是%d\n",numOne);
printf("numTwo的小数部分是%f\n",numTwo);
return 0;
}
hello.c: In function 'main':
hello.c:6:38: warning: format '%d' expects argument of type 'int', but argument 2 has type 'double' [-Wformat=]
printf("numOne的整数部分是%d\n",numOne);
^
hello.c:7:38: warning: format '%f' expects argument of type 'double', but argument 2 has type 'int' [-Wformat=]
printf("numTwo的小数部分是%f\n",numTwo);
^
numOne的整数部分是1218162008
numTwo的小数部分是2.500000