You are viewing a single comment's thread. Return to all comments →
TOOK ME A WHILE, but since I did it in C, I'm proud of myself.
Sorry if it's not the greatest, but it's the best I could come up with.
struct Num { char value; struct Num * next; struct Num * past; } typedef Num; struct NumHeader { Num * frst; Num * last; } typedef NumHeader; Num* create_next_num(Num* aux) { Num* num = malloc(sizeof(Num)); num->next = NULL; num->past = aux; return num; } /* ASCII -> { int 48 -> char '0' int 49 -> char '1' int 50 -> char '2' int 51 -> char '3' int 52 -> char '4' int 53 -> char '5' int 54 -> char '6' int 55 -> char '7' int 56 -> char '8' int 57 -> char '9' } */ void extraLongFactorials(int n) { NumHeader* header = malloc(sizeof(NumHeader)); header->frst = malloc(sizeof(Num)); header->last = header->frst; header->frst->value = '1'; header->frst->next = NULL; header->frst->past = NULL; while (n > 1) { Num* aux = header->frst; Num* aux2 = aux; int carry = 0; while (aux2 != NULL){ // Multiplication loop aux = aux2; int num = aux->value - 48; num *= n; num += carry; carry = num/10; aux->value = num - carry*10 + 48; aux2 = aux->next; } while (carry > 0) { // Carry loop aux->next = create_next_num(aux); aux = aux->next; aux->value = carry%10 + 48; carry /= 10; } header->last = aux; n--; } Num* printer = header->last; while (printer != NULL) { printf("%d", printer->value - 48); printer = printer->past; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Extra Long Factorials
You are viewing a single comment's thread. Return to all comments →
TOOK ME A WHILE, but since I did it in C, I'm proud of myself.
Sorry if it's not the greatest, but it's the best I could come up with.