Created
June 8, 2009 16:22
-
-
Save twopoint718/125913 to your computer and use it in GitHub Desktop.
estimate Euler's constant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class e | |
{ | |
public static void main(String[] args) | |
{ | |
int iterations = Integer.parseInt(args[0]); | |
double result = 0; | |
for (int i = 0; i < iterations; i++) | |
result = result + 1.0 / fact(i); | |
System.out.println("e estimated with " + iterations + " terms: " + | |
result); | |
} | |
public static long fact(int n) | |
{ | |
long result = 1; | |
for (int i = n; i > 1; i--) | |
result = i * result; | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment