很简单的东西,为什么非要递归呢~~
#include <iostream>
using namespace std;
int main()
{
int i=1,k=1;
do
{
i=i+k;
k=k+i;
cout <<' ' <<i<< ' '<<k;
}
while ( k<=32000);
}
#include <iostream>
using namespace std;
int main()
{
double a[100];
int k=0;
a[0]=1;
a[1]=1;
for (;k<=100 ;++k )
{
a[k+2]=a[k+1]+a[k];
cout << a[k] <<endl;
}
}
int F(int i)
{
if (i<1) return 0;
if (1 == i) return 1;
return F(i-1)+F(i-2);
}
#include<iostream>
using namespace std;
void fun(double *a, int n)
{
if(a[n-2] < 0.0001)
fun(a, n-1);
if(a[n-3] < 0.0001)
fun(a, n-2);
a[n-1] = a[n-2] + a[n-3];
}
int main()
{
double a[100] = {1.0, 1.0};
fun(a, 100);
for(int i=0; i<100; i++)
{
cout.width(15);
cout << a[i] ;
if((i+1)%5 == 0)
cout << endl;
}
return 0;
}