For Loop?

Hello again! I am trying to solve this:
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 positive number that is evenly divisible by all of the numbers from 1 to 20?


So i thought: Do the minimal value 2520 since we know there is no lower value, and i wanted to do a for loop. It adds a number to 2520, module by another for with maximum value of 20 and check if all == 0, but it seem not to work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 #include <iostream>
using namespace std;
int main()
{
	int max = 0;
	for (int i = 2520; i < 10000; i++)
	{
		for (int j = 1; j < 20; j++)
		{
			// Here i need to do smth like i%j == 0 but it needs to freeze i and do j 20 times so as to verify with 20 divisor and then continue and repeat.
			
		}
	}
	system("PAUSE");

}


Thanks!!
See if i is divisible by the numbers 2-20 in a loop. If you find a case where it is NOT divisible then break out of the loop:
1
2
3
4
5
6
7
8
int factor;
for (factor=2; factor <= 20; ++factor) {
    if (i % factor) break;
}
if (factor > 20) {
   // it's evenly divisible by all 20 numbers!
   cout << i << " is divisible by all numbers 1-20\n";
}

Excelent! Thank you very much, finally understood.

-Delsh
Topic archived. No new replies allowed.