import java.io.*;
public class hw7_18a {

    public static void main(String args[])throws IOException {
     BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
     System.out.print("請輸入費氏數列項數m:");
     int m=Integer.parseInt(buf.readLine());
     System.out.println("費氏數列第"+m+"項數的值為"+fib(m));
    }
    public static long fib(int n){
     int num[]=new int[n];
     num[0]=1;
     num[1]=1;
     for (int i=2;i      num[i]=num[i-1]+num[i-2];
     }
     return num[n-1];
    }   
}
--------------------Configuration: --------------------
請輸入費氏數列項數m:46
費氏數列第46項數的值為1836311903

Process completed.

我的寶貝,
用FOR迴圈寫真是快多囉!
遞迴~~什麼鳥東東嘛!



全站熱搜
創作者介紹
創作者 arthurliu 的頭像
arthurliu

arthurliu's blog

arthurliu 發表在 痞客邦 留言(0) 人氣()