斐波那契数的实现
#include <stdlib.h>
int main(int argc,char argv[])
{
int n;
int fn;
int fn2;
int fn1;
int i;
printf("请输入数列项数==> ");
scanf("%d",&n);
if(n <= 1)
{
printf("[%d]\n",n);
}
else
{
fn2 =0;
fn1=1;
printf("[0][1]");
for(i=2;i<=n;i++)
{
fn = fn2+fn1;
printf("[%d]",fn);
fn2=fn1;
fn1=fn;
}
printf("\n");
}
}
int main(int argc,char argv[])
{
int n;
int fn;
int fn2;
int fn1;
int i;
printf("请输入数列项数==> ");
scanf("%d",&n);
if(n <= 1)
{
printf("[%d]\n",n);
}
else
{
fn2 =0;
fn1=1;
printf("[0][1]");
for(i=2;i<=n;i++)
{
fn = fn2+fn1;
printf("[%d]",fn);
fn2=fn1;
fn1=fn;
}
printf("\n");
}
}
本然用我自创的CC语法实现一下,但还是各种原因先放着吧。
合乎自然而生生不息。。。