Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class problem
- {
- static void Main()
- {
- Problem();
- Solution();
- }
- static void Problem()
- {
- Console.WriteLine("\nBy considering the terms in the Fibonacci sequence whose values do not exceed\nfour million, find the sum of the even-valued terms:");
- }
- static void Solution()
- {
- int a = 1;
- int b = 1;
- int c = 0;
- int sum = 0;
- int cap = 4000000;
- do
- {
- c = a + b;
- if (c % 2 == 0)
- sum += c;
- a = b;
- b = c;
- } while (c <= cap);
- Console.WriteLine("\n{0}\n",sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment