读书人

Fibonacci sequence 用C解决

发布时间: 2012-03-30 17:32:09 作者: rapoo

求助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");

读书人网 >C语言

热点推荐