Guest User

Untitled

a guest
Feb 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #lang scheme
  2. ; Aufgabe 2.1 :
  3. ; Original:
  4. ; (+ (/ (+ 5 (* 6 3) (- 3 2))) (* 3 (- 5 4/7)))
  5. ; Fehler: Klammer falsch, Rechenzeichen falsch eingesetzt.
  6. ; Lösung:
  7. ; (+ (/ (+ 5 (* 6 3)) (- 3 2)) (* 3 (- 5 (/ 4 7))))
  8.  
  9. ; Aufgabe 2.2 :
  10. ; Original:
  11. ; (define (f x y z)
  12. ;(/ (* (- x 5 z) (* y 4 6)) (- x y)))
  13. ; Fehler: Falsche Klammern, vergessenes Rechenzeichen, vertauschte Variablen
  14. ; Lösung:
  15. ;(define (f x y z)
  16. ; (/ (* (+ x (- 5 z)) (+ 6 (* y 4))) (- y x)))
  17.  
  18. ; Aufgabe 2.3 :
  19. ; Original
  20. ;(f 1 2 3)
  21. ;(define (max x y)
  22. ;(cond ((> x y) y))
  23. ;(<= x y) x)
  24. ; Fehler: Klammern falsch, falsche Variable als Ausgabe, >(=) vergessen
  25. ;(define (max x y)
  26. ; (cond ((>= x y) x)
  27. ;((<= x y) y)))
  28. ;(max 2 5)
  29. ;(max 10 23)
  30.  
  31. ; Aufgabe 3
  32. ;(define (my-if kondition then-clause else-clause)
  33. ;(cond (kondition then-clause)
  34. ;(else else-clause)))
  35. ;
  36. ;(define (summe-von-1-bis-n n)
  37. ;(my-if (= n 0)
  38. ;0
  39. ;(+ n (summe-von-1-bis-n (- n 1)))))
  40.  
  41. ; Durch die "my-if" Funktion wir die immer "summe-von1-bis-n" Funktion vorher ausgeführt. Diese Operation
  42. ; führt wieder die Operanden aus. Dadruch eine Endlosschlauf, die den Speicher schnell füllt
  43. ; Mit If:
  44. ;(define (summe-von-1-bis-n n)
  45. ;(if (= n 0)
  46. ;0
  47. ;(+ n (summe-von-1-bis-n (- n 1)))))
  48. ; "If" Ist eine sogenannte special-form
Add Comment
Please, Sign In to add comment