Question

Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2...

Write the function below in scheme/lisp programming language. Drracket

Exercise: It is well known that n^2 is equal to the sum of the first n odd numbers.
For example, 16 = 4^2 = 7 + 5 + 3 + 1.

Write a function that takes as input a natural number, n, and that returns
the square of its input by adding the first n odd numbers. Your code may not
contain delayed operations and must use accumulative recursion.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(defun sum-odds(number)
(do ((sum 0)
(i 1 (1+ i)))
((= i number*number) sum)
(when (oddp i)
(incf sum i))))

(sum-odds 4)
=> 15

Add a comment
Know the answer?
Add Answer to:
Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT