zoukankan      html  css  js  c++  java
  • SICP:1.31按照公式求Pi值,原理同1.29

    #lang racket
    ;product doing the multiplation
    (define (product term a next b)
      (if (< b a)
          1
          (* (term a)
         (product term (next a) next b))
       );if
      );product
    
    (define (product-iteration term a next b)
      (define (iteration a result)
        (if (< b a)
        result
        (iteration (next a) 
               (* result (term a));*
               );iteration
        );if
        );iteration
      (iteration a 1)
      );product-iteration
    
    
    (define (get-pi n)
      (define a 1.0)
      (define (odd-num c) 
        (+ 1 (* 2 c));+
        );odd-num
      (define (even-num c)
        (* c 2));even-num
      (define (term1 c)
        (/ (even-num c)
           (odd-num c));/
        );term1
      (define (term2 c)
        (/ (+ 1 (odd-num c))
           (odd-num c));/
        );term2
      (define (next c)
        (+ c 1));next
      
      (* 4
         (product-iteration term1 a next n)
         (product-iteration term2 a next n))
      );get-pi
    
    (get-pi 1000)
    (get-pi 10000)

  • 相关阅读:
    Java 学习资料
    01 html5
    vscode 插件推荐
    08 css高级
    07 css定位
    06 css布局浮动
    05 css盒子
    04 css复合选择器 标签 行高
    03 css字体样式
    02 css基础选择器
  • 原文地址:https://www.cnblogs.com/wizzhangquan/p/4374481.html
Copyright © 2011-2022 走看看