Skip to content

Instantly share code, notes, and snippets.

@gabeb1920
Created February 1, 2016 23:31
Show Gist options
  • Save gabeb1920/b543031d6a31b93b7784 to your computer and use it in GitHub Desktop.
Save gabeb1920/b543031d6a31b93b7784 to your computer and use it in GitHub Desktop.
Euler Project 1 in C#
class Program
{
static void Main(string[] args)
{
int totalSum = CalculateSumOfMultiples(3, 1000) + CalculateSumOfMultiples(5, 1000) - CalculateSumOfMultiples(15, 1000);
Console.WriteLine("The sum of all multiples of 3 and 5 below 1000 is: " + totalSum);
Console.ReadLine();
}
private static int CalculateSumOfMultiples(int divisor, int max)
{
int sum = 0;
for(int i = 0; i * divisor < max; ++i)
{
sum += i * divisor;
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment