diff --git a/archives/5/current b/archives/5/current new file mode 100755 index 0000000..fe9e79f Binary files /dev/null and b/archives/5/current differ diff --git a/archives/5/src/main.c b/archives/5/src/main.c new file mode 100644 index 0000000..ed603b2 --- /dev/null +++ b/archives/5/src/main.c @@ -0,0 +1,29 @@ +#include +#include "utils.h" + +/* +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? + +https://projecteuler.net/problem=5 +*/ +int main(int argc,char**argv) { + int numb=1; + while (true) { + boolean isDivisible=true; + for (int i=1;i<=20;i++) { + if (numb%i!=0) { + isDivisible=false; + break; + } + } + if (isDivisible) { + printf("%d is divisible!",numb); + break; + } else { + numb++; + } + } + return 0; +} \ No newline at end of file diff --git a/archives/5/src/utils.h b/archives/5/src/utils.h new file mode 100644 index 0000000..d785fa2 --- /dev/null +++ b/archives/5/src/utils.h @@ -0,0 +1,7 @@ +#define true 1 +#define false 0 +#define boolean char +struct String{ + int length; + char*str; +}; \ No newline at end of file diff --git a/current b/current index f04183a..fe9e79f 100755 Binary files a/current and b/current differ diff --git a/src/main.c b/src/main.c index 0e22600..ed603b2 100644 --- a/src/main.c +++ b/src/main.c @@ -2,65 +2,28 @@ #include "utils.h" /* -A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. +2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. -Find the largest palindrome made from the product of two 3-digit numbers. +What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? -https://projecteuler.net/problem=4 +https://projecteuler.net/problem=5 */ - -struct String numberToString(int numb) { - int placeValues=0; - int tempNumb=numb; - while (tempNumb>0) { - tempNumb/=10; - placeValues++; - } - char*finalStr=malloc(placeValues+1); - tempNumb=numb; - int marker=placeValues-1; - while (tempNumb>0) { - finalStr[marker--]='0'+(tempNumb%10); - tempNumb/=10; - } - struct String str={placeValues,finalStr}; - return str; -} - -boolean isPalindrome(struct String numb) { - int offset=0; - while (offset0;numb1--) { - for (numb2=999;numb2>0;numb2--) { - struct String str = numberToString(numb1*numb2); - if (isPalindrome(str)) { - printf("%d is a Palindrome!\n",numb1*numb2); - if (maxPal