Note: All code should be written within this template directory. Test cases have been provided in the folder tests, and can be run using make test.


In this assignment, we will implement a data structure to store Big Integers. Big Integers are used to represent integers that are larger than the size of int supported by the language/system.

Big Integer Library

Create a library to support the following operations with big integers. (For simplicity, you may assume that the size of big integers will be at most 512 digits):
  1. bigint make_bigint(char* str): Parse a string and make it a Big Integer
  2. void print_bigint(bigint big_num): Prints the Big Integer
  3. bigint int_to_bigint(int num): Creates and sets a bigint to value num
  4. bigint init_bigint(): Creates and sets the bigint value to zero
  5. int compare_bigint(bigint a, bigint b): Compares two bigints and returns 0 if equal, +1 if a > b and -1 if a < b
  6. bigint zero_adjustment(bigint big_num): Zero justify a number. Makes -0 in the result to +0 if bigint's valuation is zero.
  7. bigint shift_by_power_of_10(bigint big_num, int d): Multiply a big int with 10d
  8. bigint bigint_add(bigint a, bigint b): Adds two bigints and returns the result (a + b) which is a bigint
  9. bigint bigint_sub(bigint a, bigint b): Subtracts two bigints and returns the result (a - b) which is a bigint
  10. bigint bigint_mul(bigint a, bigint b): Multiplies two bigints and returns the result (a * b) which is a bigint
  11. bigint bigint_div(bigint a, bigint b): Divides two bigints and returns the result (a / b) which is a bigint
Extra credit: Use malloc and suitably modify the functions above so that one can define arbitrary length bigints (viz. arbitrary number of digits)

Factorial using Big Integers

In this exercise, you will use the Big Integer library you just wrote to compute the factorial of numbers.
  1. Input:100
    Output: 933262154439441526816992388562667004907159682643816214685929638
    9521759999322991560894146397615651828625369792082722375825118521091686
    4000000000000000000000000

Calculator (Big Integer Shell)

A basic command interface has been written for you in main.c, which allows you to enter commands like set 100000, etc. to set a bigint to 100000. After each command, the result is to be printed. As you implement the above functions, uncomment the corresponding function calls to them (these have been marked with a NOTE), and test them out. Once you are done, remove the debug print statements (also marked with a NOTE).

The following commands are supported by the basic shell,

Important: Please read the submission guidelines before you submit your code.