May 2021 1 230 Report
Scheme - Average Function?

I'm trying to write a function in scheme to average a list. So far I have a function that will add everything up, but that won't work. What I want to to is get the first and second from each list, add them up, and then call avg on the rest of the list. Any suggestions?

(define a 0)

(define (avg N)

(if (null? N)

0

(+ (car N) (avg (cdr N) ) )

))


Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments




Helpful Social

Copyright © 2024 Q2A.MX - All rights reserved.