Project Euler #6

The problem:

The sum of the squares of the first ten natural numbers is,

1^(2) + 2^(2) + … + 10^(2) = 385

The square of the sum of the first ten natural numbers is,

(1 + 2 + … + 10)^(2) = 55^(2) = 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.

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:

  1. palindrome
  2. Getting a Prime
  3. revisit to project euler with c++
  4. Project Euler is awesome

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>