数值运算实验记录
2011-08-18 14:47
253 查看
实验环境:
OS: Windows 7
IDE: Visual Studio 2010 Pro
实验代码1:
运行结果:
0
实验代码2:
0.333333
实验代码3:
0.166667
实验分析:
结论:
int/int类型的计算值,只保留整数部分,小数部分被舍弃,并且不对运算结果作四舍五入的处理。
float/int类型的计算值,精确到小数点后6位,对运算结果作四舍五入处理。
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/int | float/int | float/int | float/int |
被除数 | 1 | 1 | 1 | 1 |
除数 | 2 | 2 | 3 | 6 |
实验值 | 0 | 0.5 | 0.333333 | 0.166667 |
理论值 | 0.5 | 0.5 | 0.333333... | 0.166666... |
int/int类型的计算值,只保留整数部分,小数部分被舍弃,并且不对运算结果作四舍五入的处理。
float/int类型的计算值,精确到小数点后6位,对运算结果作四舍五入处理。
相关文章推荐
- 数据表记录包含表索引和数值,请对表索引相同的记录进行合并,即将相同索引的数值进行求和运算,输出按照key值升序进行输出。 输入描述: 先输入键值对的个数 然后输入成对的index和value值,以
- 数据表记录包含表索引和数值,请对表索引相同的记录进行合并,即将相同索引的数值进行求和运算,输出按照key值升序进行输出。
- 数据表记录包含表索引和数值,请对表索引相同的记录进行合并,即将相同索引的数值进行求和运算,输出按照key值升序进行输出。
- 数据表记录包含表索引和数值,请对表索引相同的记录进行合并,即将相同索引的数值进行求和运算,输出按照key值升序进行输出
- 关于MATLAB入门的简单记录10 Matlab的数值运算
- Mathematica 基本数值运算与符号运算函数
- 第十五周实验报告2(分数四则运算窗口程序)
- 【PHP内核】语法:不同类型之间数值运算的实现
- 2018-3-14晚上工作记录---成功将实验完完整整地跑出来了,开心
- 佛科院数值分析实验
- 六、STL的数值计算---数组(向量)运算---数组子集类-slice类和slice_array类模板
- javascript两个数值简单运算精度修正函数
- 实验记录三 通用输入输出(GPIO)
- Kafka 安装配置 及 简单实验记录
- VWG KeyUp 事件处理实验记录
- 实验2_数据类型与运算_参考答案
- hdu 3000 A Simple Language (逆波兰式计算四则运算表达式数值)
- Shell编程---数值运算
- SDN初探–openflow实验记录(ubuntu+mininet+opendaylight)
- 【课程记录】用Ego1开发板做流水灯实验并理解程序的模块调用