zoukankan      html  css  js  c++  java
  • Problem2-Project Euler

    Even Fibonacci numbers

     

    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.

    找出400 0000以下斐波那契数中的偶数求和,累加即可(用递推公式,通项公式可能有舍入误差)

     1 #include"stdio.h"
     2 
     3 int main()        /*problem2-Even Fibonacci numbers*/
     4 {
     5     int a[100]={1,1,2},i;
     6     double sum=0;
     7     for(i=3;;i++)
     8     {
     9         a[i]=a[i-2]+a[i-1];
    10         if(a[i]>4000000.0||i==100)
    11             break;
    12     }
    13     for(i=2;a[i]!=0;i+=3)
    14         sum+=a[i];
    15     printf("sum is %lf
    ",sum);
    16     return(0);
    17 }
    View Code
  • 相关阅读:
    HUD--2553 N皇后问题
    poj--2139
    poj--2236
    poj--2229
    poj--2376 Cleaning Shifts
    poj--3669
    poj--1979 Red and Black
    poj--1258
    经典DP问题--poj1088滑雪
    Poj 1041--欧拉回路
  • 原文地址:https://www.cnblogs.com/redlogic/p/8536472.html
Copyright © 2011-2022 走看看