0

Only functions allowed are write and malloc.

I need to be able to calculate something like 45645646554665466546546456456448798789456456465789745321321231231231231231231231231321231321231321231467 * 45645646554665466546546456456448798789456456465789745321321231231231231231231231231321231321231321231467 - (4564564655466546654654645645644879878945645646578974532132123123123123123123123123132123132123132123146745645646554665466546546456456448798789456456465789745321321231231231231231231231231321231321231321231467 + 456456465546654665465464564564487987894564564657897453213212312312312312312312312313212313212313212314674564564655466546654654645645644879878945645646578974532132123123123123123123123123132123132123132123146745645646554665466546546456456448798789456456465789745321321231231231231231231231231321231321231321231467)

How would I go about doing this(and in arbitrary bases to boot, ie. up to base 128 if necessary).

I'm thinking addition/subtraction/multiplication won't be too bad, just very tedious, but it seems like modulus/division will be trouble.

Ôrel
  • 7,044
  • 3
  • 27
  • 46
  • I've already done the "easy" parts. I've made a recursive descent parser to evaluate the expression, a function to evaluate the result and to convert it to whatever base I wish(up to 16 for now), but now I'll need to change everything to handle infinitely large inputs that won't fit in a long long as well as extremely large results. I'm thinking of making functions for each, and I'm thinking of a linked list or array to do addition/subtraction/multiplication, but while I'm working on validation to ensure the expression is valid, I'd like to see if there are more efficient ways to tackle it. –  Jan 10 '18 at 05:07
  • Perhaps you can use some library like GMP. – rcs Jan 10 '18 at 05:08
  • No external libraries are allowed. Read to read the input from stdin, write to output the result and error messages, malloc, and free are the only functions permitted for the assignment. –  Jan 10 '18 at 05:10
  • By the way, in a deleted answer on the link I provided above was a reference to [this C program](http://www3.cs.stonybrook.edu/~skiena/392/programs/bignum.c) which may or may not be of help to you. – Patrick Roberts Jan 10 '18 at 05:13
  • Thanks a ton, I was searching up methods to do it with a string/struct, but I never really considered anything else as I was googling. Arbitrary-precision arithmetic seems like an exact answer to my question provided I can only do it with the 4 functions provided, and that C program seems to be a good reference. Thank you. –  Jan 10 '18 at 05:16

0 Answers0