Project Euler #6
The problem:
The sum of the squares of the first ten natural numbers is,
12 + 22 + … + 102 = 385The square of the sum of the first ten natural numbers is,
(1 + 2 + … + 10)2 = 552 = 3025Hence 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.
My solution:
Public Sub Difference() Dim iStart, iEnd, iSumOfSquares, iSquareOfSum As Integer iStart = 1 iEnd = 100 iSumOfSquares = 0 iSquareOfSum = 0 For iCounter As Integer = iStart To iEnd iSumOfSquares = iSumOfSquares + iCounter ^ 2 iSquareOfSum = iSquareOfSum + iCounter Next Response.Write(iSquareOfSum ^ 2 - iSumOfSquares) End Sub
Related posts:







No comments yet.