From cd45b25f9f94e920981e893d6fd557221edd744b Mon Sep 17 00:00:00 2001 From: Joy Lakra Date: Sun, 20 Oct 2019 09:13:23 +0530 Subject: [PATCH] EvenFibonacciSum solution added --- Solutions/even-fibonacci.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Solutions/even-fibonacci.cpp diff --git a/Solutions/even-fibonacci.cpp b/Solutions/even-fibonacci.cpp new file mode 100644 index 0000000..5a8be09 --- /dev/null +++ b/Solutions/even-fibonacci.cpp @@ -0,0 +1,30 @@ +/*Given a number N, we have to find the sum of even fibonaccci nos. + less than the given number N. + Code by iamJL + */ +#include +using namespace std; +int fib[10000]; +int main() +{ + int t; + cin>>t; + fib[0]=1,fib[1]=2; + while(t--) + { + int n,i=2; + cin>>n; + int sum = 2; + while(1) + { + fib[i]=fib[i-1]+fib[i-2]; + if(fib[i]>n) + break; + if(fib[i]%2==0) + sum+=fib[i]; + i++; + } + cout<