Project Euler -> problem 2
2013-08-22 15:33
330 查看
2. 斐波那契数列中的每一项被定义为前两项之和。从1和2开始,斐波那契数列的前十项为:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
考虑斐波那契数列中数值不超过4百万的项,找出这些项中值为偶数的项之和。
int main(void)
{
int
a[3]={1,2,0},i=0;
while(a[2]<4000000){
a[2] = a[0] + a[1];
if(a[1]%2 == 0)
i+=a[1];
a[0]
= a[1];
a[1]
= a[2];
}
printf("%d",i);
return
0;
}
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
考虑斐波那契数列中数值不超过4百万的项,找出这些项中值为偶数的项之和。
int main(void)
{
int
a[3]={1,2,0},i=0;
while(a[2]<4000000){
a[2] = a[0] + a[1];
if(a[1]%2 == 0)
i+=a[1];
a[0]
= a[1];
a[1]
= a[2];
}
printf("%d",i);
return
0;
}
Answer: | 4613732 |
相关文章推荐
- Project Euler -> problem 3
- Project Euler -> problem 4
- Project Euler -> problem 5
- Project Euler -> problem 6
- Project Euler -> problem 7
- Project Euler -> problem 8
- Project Euler -> problem 9
- Project Euler -> problem 12
- Project Euler -> problem 1
- Project Euler -> prob 4000 lem 11
- project euler Problem 18 & 36
- projecteuler---->problem=33----Digit canceling fractions
- Project Euler Problem 30
- ZOJ 3686 A Simple Tree Problem(将对树的操作转化成区间=>线段树)
-  |"|&|<|>等html字符转义
- The7th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Who is Older?
- Test11_6&nbsp;指针用p-&gt;X和(*p).X等价
- JSP 之 JSTL_04:<c:forTokens>
- Linux-world-2012-January->16(mini2440 uboot201103 系统移植)->3(machine ID problem)
- project euler Largest prime factor&Largest palindrome product