作者oldfatty (无奸道之鱼纹肥..)
站内NTUBIME96-HW
标题[解答] 上机考第四题
时间Tue Dec 2 11:43:27 2003
#include "stdafx.h"
#include "iostream"
using std::cout;
using std::endl;
unsigned long fibonacci (unsigned long);
int main()
{
int counter;
unsigned long result;
int a;
cout << "fibonacci数列前20项" << endl;
for (counter=0;counter<=19;counter++)
{
result=fibonacci(counter);
cout<<result<<" ";
a=counter+1;
if (a%5==0)
cout <<endl;
}
return 0;
}
unsigned long fibonacci(unsigned long a)
{
if (a==0 || a==1)
return a;
else
return fibonacci(a-1)+fibonacci(a-2);
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 211.74.219.163