Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rextester.Program.Main is the entry point for your code. Don't change it.
- //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
- /**
- 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.
- **/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- new Program();
- }
- public Program(){
- double x = 1;
- double sum = 0;
- double findNXHold = findNX(x);
- while(findNXHold <= 55){
- if(findNXHold % 2 == 0){
- sum+= findNXHold;
- }
- x = x+3;
- findNXHold = findNX(x);
- }
- Console.WriteLine(sum);
- }
- public double findNX(double x){
- if(x == 0){
- return 1;
- }
- if(x == 1){
- return 2;
- }
- return 2*findNX(x-2) + findNX(x-3);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement