Sha256: aebe6926b5cad5a5011d12838654bcb09deb1bb2b013d5b5576851c79c2ab903

Contents?: true

Size: 760 Bytes

Versions: 10

Compression:

Stored size: 760 Bytes

Contents

; integer.lsp
; oofoe 2012-01-17

(define (aski msg) (print msg) (int (read-line)))
(setq x (aski "Please type in an integer and press [enter]: "))
(setq y (aski "Please type in another integer             : "))

; Note that +, -, *, / and % are all integer operations.
(println)
(println "Sum: " (+ x y))
(println "Difference: " (- x y))
(println "Product: " (* x y))
(println "Integer quotient (rounds to 0): " (/ x y))
(println "Remainder: " (setq r (% x y)))

(println "Remainder sign matches: "
	 (cond ((= (sgn r) (sgn x) (sgn y)) "both")
	       ((= (sgn r) (sgn x))         "first")
	       ((= (sgn r) (sgn y))         "second")))
	 
(println)
(println "Exponentiation: " (pow x y))

(exit) ; NewLisp normally goes to listener after running script.

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/arithmetic.integer/newlisp.txt
zettacode-0.1.6 files.zettacode/arithmetic.integer/newlisp.txt
zettacode-0.1.6 files.zettacode2/arithmetic.integer/newlisp.txt
zettacode-0.1.5 files.zettacode/arithmetic.integer/newlisp.txt
zettacode-0.1.5 files.zettacode2/arithmetic.integer/newlisp.txt
zettacode-0.1.4 files.zettacode/arithmetic.integer/newlisp.txt
zettacode-0.1.4 files.zettacode2/arithmetic.integer/newlisp.txt
zettacode-0.1.3 files.zettacode/arithmetic.integer/newlisp.txt
zettacode-0.1.2 files.zettacode/arithmetic.integer/newlisp.txt
zettacode-0.1.1 zettacode.files/arithmetic.integer/newlisp.txt