Skip to content

Instantly share code, notes, and snippets.

@twopoint718
Created June 8, 2009 16:22
Show Gist options
  • Save twopoint718/125913 to your computer and use it in GitHub Desktop.
Save twopoint718/125913 to your computer and use it in GitHub Desktop.
estimate Euler's constant
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