0
votes

I am trying to write a scheme program, but I am trying to figure out how can i do this:

suppose, I have called a function named addFunc, that takes two input numbers, computes the sum squares of each number and returns the sum of the two sum squares

in math, : if addFunc were called with 3 and 2, it will computer the sum squares of 3 as 1*1 + 2*2 + 3*3 = 14 and sum squares of 2 as 1*1 + 2*2 = 5 and then returns 19 as a result.

how can i write this in scheme programing language?

1
did you try something and it didn't work? Do you know Scheme? Did you look at any examples in Scheme? - MK.
possibly, but this one also touches on recursion. - krousey

1 Answers

1
votes

SICP is a good resource for learning scheme.

(define (sum-of-squares x)
  (if (= 1 x)
  1
  (+ (* x x) (sum-of-squares (- x 1)))))

(define (homework x y)
  (+ (sum-of-squares x) (sum-of-squares y)))