Created
June 14, 2014 15:33
-
-
Save bencoveney/12e391b8b3179aff0c5c to your computer and use it in GitHub Desktop.
Sum Square Difference
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
var limit = 100; | |
var sumOfNumbers = 0; | |
var sumOfSquares = 0; | |
// Sum the numbers and their squares | |
for(var i = 1; i <= limit; i++) | |
{ | |
sumOfNumbers += i; | |
sumOfSquares += i*i; | |
} | |
// square the sum of numbers | |
var squareOfSum = sumOfNumbers * sumOfNumbers; | |
// find the difference | |
var difference = squareOfSum - sumOfSquares; | |
console.log(difference); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment