Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Solutions/even-fibonacci.cpp
Original file line number Diff line number Diff line change
@@ -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<bits/stdc++.h>
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<<sum<<endl;
}
return 0;
}