您的位置:首页 > 其它

数值运算实验记录

2011-08-18 14:47 253 查看
实验环境:

OS: Windows 7

IDE: Visual Studio 2010 Pro

实验代码1:

#include <iostream>
using namespace std;

int main()
{
int a = 1;
int b = 6;
int c = a/b;
cout<< c <<endl;
system( "pause" );
return 0;
}

运行结果:

0

实验代码2:

#include <iostream>
using namespace std;

int main()
{
int a = 1;
int b = 3;
float c = ( float )a/b;
cout<< c <<endl;
system( "pause" );
return 0;
}
运行结果:

0.333333

实验代码3:

#include <iostream>
using namespace std;

int main()
{
int a = 1;
int b = 6;
float c = ( float )a/b;
cout<< c <<endl;
system( "pause" );
return 0;
}
运行结果:

0.166667

实验分析:

类型int/intfloat/intfloat/intfloat/int
被除数1111
除数2236
实验值00.50.3333330.166667
理论值0.50.50.333333...0.166666...
结论:

int/int类型的计算值,只保留整数部分,小数部分被舍弃,并且不对运算结果作四舍五入的处理。

float/int类型的计算值,精确到小数点后6位,对运算结果作四舍五入处理。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  float windows c ide 2010 os
相关文章推荐