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
  • Digg
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Facebook
  • Google Bookmarks
  • Live

Related posts:

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

  1. No trackbacks yet.