Please use the scheme programming language with Dr Racket Cr
Please use the scheme programming language with Dr. Racket
Create a recursive procedure called (sumOdds lst), where lst is a list of numbers. The procedure should return the sum of all odd numbers on the list. When the list is empty, the result should be 0.
Test case: (sumOdds \'(1 3 4 5 6 -7)) -->2
Use an unnamed procedure to implement this task:
((lambda (lst) (add code here) \'(1 3 4 5 6 -7)) where the list \'(1 3 4 5 6 -7) is the argument
Solution
(define (sumOdds lst) (cond ((null? lst) 0) ((odd? (car lst)) (+ (car lst) (sumOdds (cdr lst)))) (else (sumOdds (cdr lst)))))