双阵列的总和与e获得不正确的答案
Sum of double array gets incorrect answer with e
我遇到了双元素总和的怪异错误,看起来像1E 002,当答案为double sum。
const int ARRAY_SIZE =20;
//Index variable
int i;
//For finding average
double sum=0.00;
cout.precision(2);
srand((unsigned)time(0));
double main_array[ARRAY_SIZE];
//Header
cout << "Element number tt" << "Random Numbernn" << endl;
//Assigning random values into array.
for (i=0; i< ARRAY_SIZE; i++)
{
//Randomizer
double ran =(rand()/((float)RAND_MAX/(10-0)));
main_array[i] = ran;
sum+=main_array[i];
字母e
表示科学符号。它的存在不会使值"不正确"。
使用std::fixed
流操纵器指定定点符号。
cout << fixed << sum;
相关文章:
- 使用2个键的cpp-stl::优先级队列排序不正确
- 正弦级数方程计算不正确
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 密码登录程序将永远循环并显示不正确的结果
- 在C++中返回不正确的楼层函数值
- 形状对象的旋转和缩放不正确C++
- C++ 读取文件读取文件不正确
- 关于类的 Python 文档 - 对C++的引用不正确
- 特征 LLT 模块给出不正确的结果?
- 为什么C++程序在太大时返回代码而不是答案?
- glibcxx STL 在实现 std::valarray::sum() 时是否不正确?
- 如果语句逻辑不正确
- 来自逆 vp 矩阵和相机位置的光线方向不正确
- 指向对象的内存位置的指针已在程序中删除,但仍提供正确答案而不是垃圾值
- 双阵列的总和与e获得不正确的答案
- 函数的答案不正确
- 为什么此代码不显示计算的正确答案,为什么它会无限循环?
- C++考试修订版,不确定为什么正确答案是什么
- 如果通过循环求和,下面的程序会找到正确的答案,但如果通过GP的公式求和,则会找到不正确的答案.为什么
- 为什么Boost VF2子图同构给出一个不正确的答案