Skip to content

Instantly share code, notes, and snippets.

@bencoveney
Created June 14, 2014 15:33
Show Gist options
  • Save bencoveney/12e391b8b3179aff0c5c to your computer and use it in GitHub Desktop.
Save bencoveney/12e391b8b3179aff0c5c to your computer and use it in GitHub Desktop.
Sum Square Difference
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