| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6193 人关注过本帖
标题:求Fibonacci数列前40个数,要怎么编呀,谢谢大家的帮忙
只看楼主 加入收藏
GB21XY
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-7-5
收藏
 问题点数:0 回复次数:4 
求Fibonacci数列前40个数,要怎么编呀,谢谢大家的帮忙
求Fibonacci数列前40个数,这个数的特点:第1,2两数为1,从第3个数开始,该数是其前面两个数之和。即:1,1,2,3,5,8,13,21,34,55,89,144,233……

这个要怎么编呀,谢谢大家的帮忙
搜索更多相关主题的帖子: Fibonacci 之和 特点 
2005-07-05 21:58
指向指针的指针
Rank: 1
等 级:新手上路
帖 子:339
专家分:0
注 册:2004-8-8
收藏
得分:0 
FIBONACCI的定义嘛,用函数递归讪

/sign.png" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www./sign.png');}" onmousewheel="return imgzoom(this);" alt="" />
2005-07-06 18:01
指向指针的指针
Rank: 1
等 级:新手上路
帖 子:339
专家分:0
注 册:2004-8-8
收藏
得分:0 

#include<stdio.h> int Fibonacci(int a) { if(a>2)return Fibonacci(a-1)+Fibonacci(a-2); else return 1; }

void main() { int a; long int sum=0; scanf("%i",&a); for(int c=1;c<=a;c++) { sum+=Fibonacci(c); printf("%i %li \n",c,sum); } } 好像效率不高,


/sign.png" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www./sign.png');}" onmousewheel="return imgzoom(this);" alt="" />
2005-07-06 18:58
指向指针的指针
Rank: 1
等 级:新手上路
帖 子:339
专家分:0
注 册:2004-8-8
收藏
得分:0 
long int Fibonacci(int a)
{long int a1=1,a2=1,a3;
if(a&lt;3)return 1;
else
{
for(int b=1;b&lt;=(a-2);b++)
{
  a3=a1+a2;
  a1=a2;
  a2=a3;
  
}
return a3;
}
}

这个效率要高点了~~

[此贴子已经被作者于2005-7-8 10:16:22编辑过]



/sign.png" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www./sign.png');}" onmousewheel="return imgzoom(this);" alt="" />
2005-07-08 10:01
袋鼠
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2005-7-19
收藏
得分:0 
谭浩强老师的书上是这么写的:
main()
{
  long int f1, f2 ;
  int i;
  f1=1;f2=1;
  
  for(i=1;i&lt;=20;i++)
  {
    printf("%12ld%12ld",f1,f2);
    if(i%2==0)printf("\n");
    f1=f1+f2;
    f2=f2+f1;
  }
}

[此贴子已经被作者于2005-7-25 10:24:11编辑过]



爱编程,爱生活
2005-07-25 10:23
快速回复:求Fibonacci数列前40个数,要怎么编呀,谢谢大家的帮忙
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014329 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved