Nick
Nick

Reputation: 1

Scheme Programming Language

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?

Upvotes: 0

Views: 1170

Answers (1)

krousey
krousey

Reputation: 1798

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)))

Upvotes: 1

Related Questions