<html>
<body>
<p>
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
</p>
</body>
</html>
JavaScript
var answer = 0;
var answer2 = 0;
sum_of_squares(10);
square_of_sum(10);
function sum_of_squares(limit){
if (limit > 0){
sum_of_squares(limit-1)
}
answer += Math.pow(limit,2);
}
console.log(answer);
function square_of_sum(limit){
if (limit > 0){
square_of_sum(limit-1)
}
answer2 += limit;
answer2 = (Math.pow(answer2,2));
}
console.log(answer2);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.