Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.
(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 |
---|---|---|---|
Problem to page | 4 | 85 | |
Excel file not created as expected | 7 | 72 | |
Advice on Xojo as a development tool over VB. | 4 | 55 | |
What is wrong with the below insert statement. Getting error when executing. | 5 | 33 |
Join the community of 500,000 technology professionals and ask your questions.