Skip to content

Instantly share code, notes, and snippets.

@kylethedeveloper
Created April 9, 2018 18:44
Show Gist options
  • Save kylethedeveloper/c9045595cc85afe3af56c73ba8e50f91 to your computer and use it in GitHub Desktop.
Save kylethedeveloper/c9045595cc85afe3af56c73ba8e50f91 to your computer and use it in GitHub Desktop.
Project Euler - Problem 5 - Smallest multiple
/*
Project_5.cpp : Smallest multiple
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?
*/
#include <iostream>
using namespace std;
int main()
{
bool state = true;
int num = 1;
while (state)
{
int check = 0;
for (int i = 1; i <= 20; i++)
{
if (num % i == 0)
{
check++;
}
else
{
break;
}
}
if (check == 20)
{
cout << "The smallest positive number that is evenly divisible by" <<
"\nall of the numbers from 1 to 20 is: " << num << endl;
state = false;
}
else
{
num++;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment