so I created a program that takes in two long double numbers and some a particular form of calculation on them.
(因此,我创建了一个程序,该程序使用两个长双精度数并对其进行某种特殊形式的计算。)
but the issue is, the output for me is inf or in some compilers, 0.. So the error only occurs when I enter exponential values like say I enter 1.11224e+2121 1.11224e+2121 then I get inf or 0 but if I get something like 2.4 5.9 I get proper value. (但问题是,对我来说输出是inf或在某些编译器中为0。因此,仅当我输入指数值(例如说我输入1.11224e + 2121 1.11224e + 2121)时才会出现错误,然后得到inf或0,但是如果我得到像2.4 5.9这样的值,我得到了适当的价值。)
How do I fix this? (我该如何解决?)
here is my code
(这是我的代码)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
long double a,b,add=0,mean=0;
cin>>a>>b;
vector<long double> vector;
vector.push_back(a);
vector.push_back(b);
mean=(vector[0]+vector[1])/2;
for (int k = 0; k < 2; k++)
{
add= add+ pow((vector[k] - mean), 2);
}
cout<<add/2;
return 0;
}
ask by Jim Kelly translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…