Created
June 25, 2013 02:28
-
-
Save Softwave/5855446 to your computer and use it in GitHub Desktop.
JavaScript program to find the solution for project euler problem 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Project Euler Problem 2 */ | |
var sum = 0; | |
var num,num1,num2; | |
for (var i = 0; i < 800; i++) { | |
if (i == 0) { | |
num1 = 1; | |
num2 = 2; | |
console.log('1 \n\n2 \n'); | |
} | |
num = num1 + num2; | |
if ((num & 1) == 0) { | |
sum += num; | |
} | |
if (num >= 4000000) { | |
break; | |
} | |
num1 = num2; | |
num2 = num; | |
console.log('%d \n', num); | |
} | |
sum = sum + 2; | |
console.log('The sum is: %d \n',sum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment