factorial de un número
DESCRIPTION
Programa FactorialTRANSCRIPT
![Page 1: Factorial de un número](https://reader030.vdocuments.site/reader030/viewer/2022020218/5594122c1a28ab12618b47a5/html5/thumbnails/1.jpg)
UNIVERSIDAD AUTÓNOMA DEL ESTADO DE MÉXICO CENTRO UNIVERSITARIO UAEM ATLACOMULCO
Redes Neuronales Programa en Java Factorial Levi Guadarrama Tercero Oliver Sánchez Cruz Juan Carlos Tomas Reyes
FACTORIAL
Solución
Para solucionar el problema del factorial, se resolverá de forma recursiva.
Ejemplo:
Entrada = 5
Para calcular se multiplica el numero dado por su antecesor hasta que este sea
igual a cero en lo cual el factorial(1)=factorial(0)=1
5 * 4 * 3 * 2 * 1 * 0
Resultado = 120
Recibimos una variable de entrada N, luego llamamos a la subrutina Fact(X, Nivel) y luego se muestra el resultado del factorial
![Page 2: Factorial de un número](https://reader030.vdocuments.site/reader030/viewer/2022020218/5594122c1a28ab12618b47a5/html5/thumbnails/2.jpg)
UNIVERSIDAD AUTÓNOMA DEL ESTADO DE MÉXICO CENTRO UNIVERSITARIO UAEM ATLACOMULCO
Redes Neuronales Programa en Java Factorial Levi Guadarrama Tercero Oliver Sánchez Cruz Juan Carlos Tomas Reyes
Dentro de la subrutina Fact(X, Nivel) se realiza pregunta
Si nivel mayor a cero Entonces Llamaremos de nuevo a Fact(Temp,Nivel-1) disminuyendo en 1 a Nivel Luego actualizamos el valor : X = Temp * Nivel
Si el nivel es menor que cero Actualizamos el valor de X = 1
Luego del cálculo retornamos el valor de x
![Page 3: Factorial de un número](https://reader030.vdocuments.site/reader030/viewer/2022020218/5594122c1a28ab12618b47a5/html5/thumbnails/3.jpg)
UNIVERSIDAD AUTÓNOMA DEL ESTADO DE MÉXICO CENTRO UNIVERSITARIO UAEM ATLACOMULCO
Redes Neuronales Programa en Java Factorial Levi Guadarrama Tercero Oliver Sánchez Cruz Juan Carlos Tomas Reyes
Código en Java
Prueba
![Page 4: Factorial de un número](https://reader030.vdocuments.site/reader030/viewer/2022020218/5594122c1a28ab12618b47a5/html5/thumbnails/4.jpg)
UNIVERSIDAD AUTÓNOMA DEL ESTADO DE MÉXICO CENTRO UNIVERSITARIO UAEM ATLACOMULCO
Redes Neuronales Programa en Java Factorial Levi Guadarrama Tercero Oliver Sánchez Cruz Juan Carlos Tomas Reyes