Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
java: Calcula el numero euler basado en el factorial
public class Euler {
public static long fact(int x) {
long prod = 1;
for (int i = 1; i < x; i++) {
prod = prod * i;
}
return prod;
}
public static double euler(){
double e = 0;
for (int i = 1; i < 50; i++) {
e = e+1 / (double) (fact(i));
}
return e;
}
public static void main(String[] args) {
System.out.println("e = "+euler());
}
}
@jonerruiz

This comment has been minimized.

Copy link

jonerruiz commented May 14, 2018

Hola.
Creo que el método para calcular el factorial (fact), presenta un error en el número de iteraciones.
Saludos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.