Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***LANGUAGE IS SCHEME (R5RS)**** Recall from class the definition of number-sum, which computes the sum of the first n numbers: (define (number-sum n) (if (=

***LANGUAGE IS SCHEME (R5RS)****

image text in transcribed

Recall from class the definition of number-sum, which computes the sum of the first n numbers: (define (number-sum n) (if (= n 0) 0 (+n (number - sum (-n 1))))) (a) Adapt the function to one named (odd-sum n) that computes the sum of the first n odd numbers. (So (odd-sum 4) should return 16, the sum of the first 4 odd numbers: 1+3+5+7.) (b) Evaluate your function at 1, 2, 3, 4, 5, 6, and 7. What does this sequence of numbers look like, and does that make sense? (c) Adapt the function into (sum-from-to a b) that it computes the sum of the all integers from a to b, so (sum-from-to 3 5) should evaluate to 12. If a is greater that b, it should evaluate to 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions