首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

Fibonacci sequence ,用C解决

2012-03-30 
求助Fibonacci sequence ,用C解决.欧拉计划第二题:Each new term in the Fibonacci sequence is generated

求助Fibonacci sequence ,用C解决.
欧拉计划第二题: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.

[解决办法]

C/C++ code
#include <stdio.h>#include <stdlib.h>int main(){    int m = 1, n = 2, sum = 2, tmp;    while(n < 4000000)    {        tmp = n;        n = m + n;        m = tmp;        if(n % 2 == 0)            sum += n;    }    printf("%d\n", sum);    system("pause");    return 0;}
[解决办法]
探讨
对的,谢谢了,请教一下这一句 system("pause");

热点排行