Welcome to W3Courses
 Like Us on Facebook

Check if Even or Odd using Scheme Source Code

The following code checks if a number is Even or Odd

CODE
(define (even? n)
      (if (eqv? n 0) #t
             (odd? (- n 1))))
(define (odd? n)
      (if (eqv? n 0) #f
             (even? (- n 1))))


RESULT
> (even? 21)
#f
> (odd? 21)
#t
> (even? 50)
#t

Share