Hi,
I wrote this little program to help with figure out convergence/divergance of series... However, for not very large values of a, the program gives the answer (run-time error?) -1.#IND
I'm assuming this is because I'm bumping into a limitation of long doubles... Does anyone know of a way I could modify this program so that it can handle larger values of a?
Thanks!
-Xanth
Code:#include <iostream> #include <cmath> #include <iomanip> #define E 2.71828182846 using namespace std; int main() { int a; long double ans=0; long double temp; while (a != -2) { cout << "Enter A: "; cin >> a; for (a;a>0;a--) { temp = (pow(E, a) - 1)/(pow(E, (2*a)) - 1); ans += temp; } cout << endl << "Ans is " << setprecision(15) << ans << endl; ans=0; } return 0; }



LinkBack URL
About LinkBacks


