Chinaunix首页 | 论坛 | 博客
  • 博客访问: 215656
  • 博文数量: 68
  • 博客积分: 3120
  • 博客等级: 中校
  • 技术积分: 715
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-08 09:53
文章分类
文章存档

2012年(29)

2011年(3)

2010年(18)

2009年(18)

我的朋友

分类: C/C++

2011-04-26 22:18:33

问题:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.


答案:4613732


#include

int main(void)
{
        long int sum=0L, limit=4000000L, a=1L, b=1L, c=2L;

        while(c        {
                sum+=c;
                a=b+c;
                b=c+a;
                c=a+b;
        }
        printf("%li\n", sum);
        return 0;
}


阅读(795) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~