Sends for the fellow dear visitors:welcome to dongpad!


 Welcome to DongPad!

 msn


预览模式: 普通 | 列表

F#对斐波那契数列求和

This Article is Published by Live Writer。

如题,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!

Tags: DongPad

分类:F# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 1233 | 返回顶部