I've been working through Project Euler
Project Euler. Anyone done this before? I'm having a great time.
Basically 200 problems to be solved using programming, using any language you like. I started today; up to problem 5.
Here's my solution in C# for number 5.
Code:
public class problem5
// 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
// What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
{
public void ProblemFive(){
for (int i = 40; i != 1000000000; i++){
bool divides = checkNumber(i);
if (divides == true){
Console.WriteLine("Found it: {0}", i);
break;
}
}
}
static bool checkNumber(int number){
int i = 11;
while (i != 20){
if (number % i != 0)
return false;
i++;
}
return true;
}