Advertisement
Daniel_Casallas

Untitled

Aug 8th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.78 KB | None | 0 0
  1. ;Autores: Daniel Felipe Casallas Ortiz
  2. ;Fecha: 8/Agosto/20
  3. ;Contrato: multiplicacion: numero numero -> numero
  4. ;Descripcion:Recibe dos numeros que se evaluan entre ellos
  5. ;EJEMPLOS:
  6. (define (multiplicacion a b)
  7.   (cond
  8.     [(not (and (number? a)(number? b)))(error "La entrada debe ser un numero")]
  9.     [(= b 1) a] ;caso base
  10.     [else (+ a (multiplicacion a (- b 1)))]
  11.     )
  12.   )
  13.  
  14. (multiplicacion 2 5)
  15.  
  16. ;Autores: Daniel Felipe Casallas Ortiz
  17. ;Fecha: 8/Agosto/20
  18. ;Contrato: elevar: numero numero -> numero
  19. ;Descripcion:Recibe dos numeros que se evaluan entre ellos
  20. ;EJEMPLOS:
  21. (define (elevar a b)
  22.   (cond
  23.     [(not (and (number? a)(number? b)))(error "La entrada debe ser un numero")]
  24.     [(= b 0) 1] ;caso base
  25.     [else (* a (elevar a (- b 1)))]
  26.     )
  27.   )
  28.  
  29. (elevar 2 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement