diff --git a/archives/10/current b/archives/10/current new file mode 100755 index 0000000..d5b5ef4 Binary files /dev/null and b/archives/10/current differ diff --git a/archives/10/src/main.c b/archives/10/src/main.c new file mode 100644 index 0000000..cda1c31 --- /dev/null +++ b/archives/10/src/main.c @@ -0,0 +1,31 @@ +#include +#include "utils.h" + +/* +The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. + +Find the sum of all the primes below two million. + +https://projecteuler.net/problem=10 +*/ +int main(int argc,char**argv) { + FILE*f=fopen("archives/primegenerator/primes","r"); + long sum=0; + int ch=' '; + while ((ch=fgetc(f))!='{'); + while (true) { + int digit=0; + while ((ch=fgetc(f))!=',') { + digit*=10; + digit+=ch-'0'; + } + if (digit>=2000000) { + break; + } else { + sum+=digit; + } + } + fclose(f); + printf("\n\nThe sum of all primes below 2000000 is %ld",sum); + return 0; +} \ No newline at end of file diff --git a/archives/10/src/utils.h b/archives/10/src/utils.h new file mode 100644 index 0000000..d785fa2 --- /dev/null +++ b/archives/10/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 b7681a5..d5b5ef4 100755 Binary files a/current and b/current differ diff --git a/src/main.c b/src/main.c index c5cf62a..cda1c31 100644 --- a/src/main.c +++ b/src/main.c @@ -2,30 +2,30 @@ #include "utils.h" /* -A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, +The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. -a2 + b2 = c2 -For example, 32 + 42 = 9 + 16 = 25 = 52. +Find the sum of all the primes below two million. -There exists exactly one Pythagorean triplet for which a + b + c = 1000. -Find the product abc. - -https://projecteuler.net/problem=9 +https://projecteuler.net/problem=10 */ int main(int argc,char**argv) { - int a=1; - int b=2; - int c=997; - int sum=0; - for (b=2;b=2000000) { + break; + } else { + sum+=digit; } } + fclose(f); + printf("\n\nThe sum of all primes below 2000000 is %ld",sum); return 0; } \ No newline at end of file