revisit to project euler with c++

As a way to get reacquainted with c++, I’m revisiting all my PE problems.  Here’s the code for #1.

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

#include <iostream>

int main(int argc, char* argv[])
{
    int iMax = 1000;
    int iSum = 0;
    int iMultiplesOf[2] = { 3, 5 };
    for each (int iNum in iMultiplesOf)
    {
        for (int i = 0; i * iNum < iMax; i++)
        {
            iSum += i * iNum;
        }
    }
    std::cout << iSum << std::endl;
    system("PAUSE");
    return 0;
}
  • Digg
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Facebook
  • Google Bookmarks
  • Live

Related posts:

  1. Project Euler #6
  2. Project Euler is awesome
  1. No comments yet.

  1. No trackbacks yet.