# My first attempt at Project Euler

Published on 2011-07-20I've decided to teach myself C# by working my way through Project Euler. As I'll be learning the language along the way, I'm sure I'll be overlooking solutions that would be simple and obvious to those fully fluent in C#.

The first problem reads:

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.

I thought the simplest solution would be to iterate over all integers below 1,000 and fold any multiples of three or five into a variable. Feel free to ignore the VS preamble.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSharpEuler1 { class Program { static void Main(string[] args) { int result = 0; for (int i = 0; i < 1000; i++) { if (i % 3 == 0) { result += i; } else if (i % 5 == 0) { result += i; } } Console.WriteLine("The sum of all multiples of 3 and 5 below 1000 is {0}", result); } } }