diff --git a/archives/16/current b/archives/16/current new file mode 100755 index 0000000..72e418b Binary files /dev/null and b/archives/16/current differ diff --git a/archives/16/src/main.c b/archives/16/src/main.c new file mode 100644 index 0000000..9fd7173 --- /dev/null +++ b/archives/16/src/main.c @@ -0,0 +1,27 @@ +#include +#include "utils.h" + +/* + 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. + + What is the sum of the digits of the number 21000? + + + https://projecteuler.net/problem=16 +*/ + +int main(int argc,char**argv) { + + int i=1; + struct String numb = {1,"2"}; + while (i++<1000) { + numb = add(numb,numb); + } + //printf("%s",numb.str); + int sum=0; + for (int j=0;j +#include + +struct String add(struct String numb1, struct String numb2){ + byte carryover=0; + int digitCount=0; + char*str = malloc(0); + if (numb1.length>=numb2.length) { + for (int offset=0;offsetoffset) { + //printf("%c %c\n",numb1.str[numb1.length-offset-1],numb2.str[numb2.length-offset-1]); + int sum=((numb1.str[numb1.length-offset-1]-'0')+(numb2.str[numb2.length-offset-1]-'0'))+((carryover>0)?carryover--:0); + if (sum>=10) { + carryover=1; + sum-=10; + } + str[offset]=sum+'0'; + } else { + str[offset]=numb1.str[numb1.length-offset-1]; + } + } + } else { + + } + if (carryover>0) { + str = realloc(str,++digitCount); + str[digitCount-1]='1'; + } + for (int i=0;i +#include + +struct String add(struct String numb1, struct String numb2){ + byte carryover=0; + int digitCount=0; + char*str = malloc(0); + if (numb1.length>=numb2.length) { + for (int offset=0;offsetoffset) { + //printf("%c %c\n",numb1.str[numb1.length-offset-1],numb2.str[numb2.length-offset-1]); + int sum=((numb1.str[numb1.length-offset-1]-'0')+(numb2.str[numb2.length-offset-1]-'0'))+((carryover>0)?carryover--:0); + if (sum>=10) { + carryover=1; + sum-=10; + } + str[offset]=sum+'0'; + } else { + str[offset]=numb1.str[numb1.length-offset-1]; + } + } + } else { + + } + if (carryover>0) { + str = realloc(str,++digitCount); + str[digitCount-1]='1'; + } + for (int i=0;i