Advertisement
AntonioVillanueva

Ejercicio 7 Go calculo factorial

Apr 19th, 2023
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.49 KB | None | 0 0
  1. /*
  2. https://gocoding.org/es/ejercicios-de-pr%C3%A1ctica-de-golang/
  3. 7. Cree un programa que calcule el factorial de un número ingresado por el usuario.
  4. */
  5.  
  6. package main
  7.  
  8. import (
  9.     "fmt"
  10. )
  11.  
  12. //Calcula el factorial de un mumero
  13. func factorial(numero int) int {
  14.     tmp := numero
  15.     for numero > 1 { //while numero >1
  16.         numero--
  17.         tmp *= numero
  18.     }
  19.     return tmp
  20. }
  21.  
  22. func main() {
  23.     var numero int
  24.     fmt.Scanln(&numero)
  25.  
  26.     fmt.Printf("factorial de %v  = %v \n", numero, factorial(numero))
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement