diff --git a/src/main.c b/src/main.c index 9fd7173..19c6468 100644 --- a/src/main.c +++ b/src/main.c @@ -2,26 +2,12 @@ #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 + https://projecteuler.net/problem= */ 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;joffset) { + //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]=numb2.str[numb2.length-offset-1]; + } + } } if (carryover>0) { str = realloc(str,++digitCount);