i have to find e, which is 1/0!
+ 1/1!
+ 1/2!
+ 1/3!
... + 1/n!
given n as a parameter and i'm having trouble getting the correct answer.
public double Factorial(int n) {
long fact = 1;
for (int i = 1; i <= n; ++i) {
fact *= i;
}
return fact;
}
public double euler(int n) {
double y = 0;
for (int x = 0; x <= n; x++) {
double e = 1 / Factorial(n);
y = y + e;
}
return y;
when i input 10
, this outputs 2.7557319223985893E-6
when i should be getting 2.7182818011463845
. i ran through the code a few times but i can't figure out the issue. any help is appreciated.