Please help!! I am trying to make a C++ program that calculates the value to using the e approximation series e = 1 + 1/1! + 1/2! + 1/3! .... When I go to output the value of sumi which should be e-1 the porgram print out inf. Im assumign this means infiniy but From my calc days I know this equation tends to 0 so I really don't know what's the matter. Can anyone help me?
Here's my code:
Here's my code:
Code:
#include <iostream.h>
#include <stdlib.h>
using namespace std;
int factorial (int num){
int fac;
for(int g = 1; g <= num; g++){
fac *= g;
}
return fac;
}
int main()
{
double sumi;
for(int j = 1; j < 11; j++) {
for(int i = 1; i < j*10000; i++) {
sumi += (static_cast<double>(1)/factorial(i));
}
cout << "For an estimation of i = "<< j*10000 << " e equals " << 1 + sumi << endl;
sumi=0;
}
system("PAUSE");
return 0;
}