;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-advanced-reader.ss" "lang")((modname e18) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ())))
(define (div-three x)
(/ x 3.0))
;;(div-three 1 3)
(define (three-times x)
(* x x x))
;;(three-times 2)
(define (square x)
(* x x)
)
;;(square 2)
(define (make-nums guess x)
(+ (+ guess guess) (/ x (square guess))))
;;(make-nums 2 8)
(define (improve guess x)
(div-three (make-nums guess x))
)
;;(improve 2 8)
(define (good-enough? guess x)
(< (abs (- (three-times guess) x)) 0.001))
;;(good-enough? 2 8)
(define (cube-root-iter guess x )
(if (good-enough? guess x)
guess
(cube-root-iter (improve guess x) x)))
;;(cube-root-iter 2 8)
(define (cube-root x)
(cube-root-iter 1.0 x))
(cube-root 27)
SBM Is The Sale-and-run Type Compnay!SBM will provide the best Crushers and service for the people who need the crushers.
2013年9月29日星期日
Get the Cube root of a Number
订阅:
博文评论 (Atom)
没有评论:
发表评论