sicp-ex-1.30


 (define (itersum term a next b) 
  (define (iter a result) 
          (if (> a b) 
              result 
              (iter (next a) (+ result (term a))))) 
  (iter a 0)) 

To Test

 (define (pi-sum a b) 
  (define (pi-term x) 
          (/ 1.0 (* x (+ x 2)))) 
  (define (pi-next x) 
          (+ x 4)) 
  (itersum pi-term a pi-next b)) 
 (* 8 (pi-sum 1 1000))  

should = 3.139592655589783

 

<< Previous exercise (1.29) | sicp-solutions | Next exercise (1.31) >>