Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. /*
  5. Each new term in the Fibonacci sequence is generated by adding the previous two terms.
  6. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
  7.  
  8. By considering the terms in the Fibonacci sequence whose values do not exceed four million, f
  9. ind the sum of the even-valued terms.
  10. Result : 4613732
  11. */
  12.  
  13. double MAX_FIBO = 4000000;
  14. int result = 0;
  15.  
  16. void fibo(int a, int b){
  17.     int temp;
  18.     if(a<MAX_FIBO){;
  19.         temp = b;
  20.         b = a + b;
  21.         a = temp;
  22.  
  23.         if(a%2==0){
  24.             result=result+a;
  25.         }
  26.  
  27.     } else {
  28.         cout << result;
  29.         return;
  30.     }
  31.     fibo(a,b);
  32. }
  33.  
  34. int main(){
  35.     fibo(1,2);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement