palm0919 發表於 2007-5-18 11:46:12

窩狀函數

#include<iostream>
using namespace std;
double fib(int n)
{
if (n<=2){
          return 1;
         }
else {
      return(fib(n-1)+fib(n-2));
      }         
}      
int main()
{
   int x;
   cout<<"請輸入一整數";
   cin>>x;
   cout<<"fib("<<x<<")="<<fib(x);
   
    system ("PAUSE");
    return 0;
}
頁: [1]
查看完整版本: 窩狀函數

Checking the Pageranks