You are viewing a single comment's thread. Return to all comments →
Here for c programmers. theres still a easier code but more logical
int main(){ int t; scanf("%d",&t); for(int a0 = 0; a0 < t; a0++){ long long int n, sum =0, fib[100]; scanf("%lld",&n); fib[0] = 0; fib[1] = 1; for(long int i = 2; i < 100; i++) { fib[i] = fib[i-1] + fib[i-2]; if((fib[i] <= n) && (fib[i] % 2 == 0)) { sum += fib[i]; } if(fib[i] >= n) { i = n; } } printf("%lld\n", sum); } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #2: Even Fibonacci numbers
You are viewing a single comment's thread. Return to all comments →
Here for c programmers. theres still a easier code but more logical