#lang racket
;; 라이프니츠의 공식
(define (findpi current result add)
(cond ((> current 10000000) (* 4 result))
(else
(cond ((equal? + add) (findpi (+ current 2) (+ result (/ 1 (+ current 2))) -))
((equal? - add) (findpi (+ current 2) (- result (/ 1 (+ current 2))) +))))))
;; 오일러의 식
(define (findpi2 current result)
(cond ((> current 10000000) (sqrt (* 6 result)))
(else (findpi2 (+ current 1) (+ result (/ 1 (* current current)))) )))
댓글 없음:
댓글 쓰기