(define (fact n) ;;method to solve a factorial
(if (= n 0)
1
(* n (fact (- n 1)))))
(define count 0) ;;keeps track of progress
(define total 0) ;;keeps running total
(define (e limit)
(if (< count limit)
total
(e (+ total (/ 1 (fact (+ count 1)))))
)
)
(define (fact n) ;;method to solve a factorial
(if (= n 0)
1
(* n (fact (- n 1)))))
(define (term x) ;;method to solve a single term
(/ 1 (fact x)))
(define count -1) ;;counter variable
(define total 0) ;;variable to hold ongoing total
(define (e limit)
(if (= count limit) ;;when the limit reaches count, it outputs total
total
(+ total (term limit) (e (- limit 1))) ;;adds to the total the current term and recursively calls the next number. Counts down to -1 (so that we include 0 in our calc)
)
)
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Need To Find FireFox Binary Path For Python Selenium On Windows 7 | 15 | 426 | |
STDEVP in SQL | 2 | 54 | |
Re-position the objects | 7 | 96 | |
C# application error "Parameter Is Not Valid". | 3 | 79 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
21 Experts available now in Live!