Categories: archive |code

Project Euler #6

In JavaScript:

(function(){
  var sumSq = 0, sqSum = 0, total = 0;
  for (var i = 1; i < 101; i++){
       sumSq += Math.pow(i,2);
       total += i;
  }
  sqSum = Math.pow(total, 2);
  document.write("Square of the Sums: ", sqSum, "<br />");
  document.write("Sum of the Squares: ", sumSq, "<br />");
  document.write("Difference: ", sqSum - sumSq);
})();

on GitHub