math - Why doesn't my C++ program calculate more digits of 'e'? -
i picked c++ programming language, , i'm trying calculate digits of 'e' calculus project @ school. i'll paste pgoram i've written below. it's based on e= lim(1+1/x)^x, x-> infinity. in program, set x=100,000. set x=1,000,000 , noticed answers somehow being subjected round-off error, instead of becoming longer in length.
program:
#include <iostream> #include <math.h> using namespace std; long double sum; int main() { long double x=100000; sum= (pow((1+(1/x)),(x))); cout<<sum; } any tips/ advice in making print out more digits great. in advance.
on first hand long double limited in number of digits can produce, , because of how real numbers implemented won't produce exact results.
but, answer question can set cout's precision doing
cout.precision(15); cout << sum; also see answer more explanations , details see how print double value full precision using cout?
Comments
Post a Comment