Sends for the fellow dear visitors:welcome to dongpad!


 Welcome to DongPad!

 msn


F#对斐波那契数列求和

如题,1+1+2+3+5+8+13+…?

let sumfib n =
    let rec fib x =
        match x with
        | 1 -> 1
        | 2 -> 1
        | x -> fib(x-2)+fib(x-1)   
    let rec addfib x =
        match x with
        | 1 -> 1
        | x -> fib (x)+ addfib (x-1)   
    addfib n

cool!



评论: 0 | 引用: 0 | 查看次数: 1011 | 返回顶部
发表评论
昵 称:    
验证码:   
 
内 容:
选 项:  
 
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 500 字 | UBB代码 开启 | [img]标签 开启