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.
#include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #define N 4000000 int a[1001]; void solve() { int a,b,c,n,count=2; a=1,c=0,b=2; n=3; while(c<=N) { c=a+b; if(n%2!=0) { a=c; } else { b=c; } n++; if(c%2==0) { count+=c; } } printf("%d",count); } int main() { solve(); getchar(); getchar(); return 0; }
Answer:
|
4613732 |
相关推荐
C#,广义斐波那契数(Generalised Fibonacci Numbers)的算法 广义斐波那契序列(generalized Fibonacci sequence)是斐波那契数的推广。由递推关系F₁=F₂=…=Fm-1=0,Fₘ=1,Fm+n=Fₙ+Fn+1+…+Fn+m+1,n≥1所产生的...
An introduction to Fibonacci Numbers and the Golden Ratio.
FibonacciNumbers_Lists
Fibonacci number In mathematics, the Fibonacci numbers form a sequence defined by the following recurrence relation:
this is the Haskell code in order to calculate fibonacci numbers.
Project-2---Even-Fibonacci-numbers:项目2的Java源代码
斐波那契数字 用斐波那契数进行实验
用Verilog代码实现斐波拉切数列的生成
偶斐波那契数 问题: :
偶数斐波那契数 斐波那契数列中值不超过 400 万的项,求偶数值项的总和。
斐波那契数 这是一个命令行应用程序,用于生成。 目的是学习C ++语言功能,...Calculating 10 fibonacci numbers 0 1 1 2 3 5 8 13 21 34 $ ./test [==========] Running 4 tests from 1 test suite. [----------] Glo
Fibonacci Heap (斐波那契堆)的定义和实现。
要求使用合适的逻辑电路的设计方法,通过工具软件 logisim 进行斐波那契(Fibonacci)数列计算器设计和验证,记录实验结果,验证设计是否达到要求。 通过斐波那契(Fibonacci)数列计算器的设计、仿真、验证 3 个训练...
Fibonacci(斐波那契)数列的JAVA解法,包含了斐波那契数列常见问题的一些算法。
欧拉公式求长期率的matlab代码欧拉计划 ...将您的过程解决方案编码到lib/even_fibonacci.rb文件中。 将您的面向对象的解决方案编码到lib/oo_even_fibonacci.rb文件中。 运行learn直到所有RSpec测试通过。 来源 --
Fibonacci斐波那契数列,很简单,就是一个递归嘛,学任何编程语言可能都会做一下这个。 最近在玩Python,在粗略的看了一下Learning Python和Core Python之后,偶然发现网上有个帖子Python程序员的进化写的很有意思。...
递归方法 def fibonacci(n): if n <= 1: return n else: return fibonacci(n-1) + fibonacci(n-2) n = int(input("请输入要计算的斐波那契数列的项数:")) print("斐波那契数列的第", n, "项为:", fibonacci(n)) 2....
The Fibonacci numbers Fn are defined as follows: F0 is 1, F1 is 1, and Fi+2 = Fi + Fi+1 , where i = 0, 1, 2, . . . . In other words, each number is the sum of the previous two numbers. The first few ...
根据给定的n值,计算Fibonacci数 程序输出FIB(n)
斐波那契数列: 在数学上它以递归的方式进行定义,指这样的一个数列:0、1、1、2、3、5、8、13、21、34、55、89、144……,即前两个数为分别为0和1,从第3项开始,每项的值都等于其前两项之和。斐波那契数列Fib(n)用...