Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please give the correct answer to the following program in C language Exercise: BigNum You are required to complete the implementation of the BigNum so
please give the correct answer to the following program in C language
Exercise: BigNum You are required to complete the implementation of the BigNum so that the add program works as expected. Specifically, you need to provide implementations for the following functions: Note that the following functions use the convention that if the function only reads a struct parameter, then it's passed by value. However, if the intention of the function is to change the value of the struct, then it is passed by reference (i.e. using a pointer). void initBigNum(BigNum *n, int Nbytes) Initialise a BigNum object by setting the byte counter and by creating (malloc'ing) an array of length Nbytes. Use an assert(to check whether the array was successfully created. No return value. void showBigNum(BigNum n) Display the contents of a BigNum on standard output. Ignore leading 'O' digits and then display all digits to the (lower) end of the array. If there are no non-'0'. digits in the array, then print a single 0. Do not print any other characters except the digits. No return value. int scanBigNum(char *s, BigNum *n) Convert a string into a BigNum. Ignores any leading space characters in the string. If the first non-space is a digit, then scan to a non-digit (or end of string) and note where the last digit occurs. Then scan the digit-rich region of the string (i.e. a contiguous sequence of digits) and place them in the appropriate location in the Bignum's array. If the string does not contain a sequence of digits after the spaces, then return 0; otherwise return 1. void addBigNums (BigNum n, BigNum m, BigNum *res) Add the values in n and m and store the result in res. If res is not initially large enough to hold the result, increase its size. No return value. void freeBigNum(BigNum n) Free any memory that was created inside the BigNum. Note do not actually free the struct for the BigNum itself as that is never malloced. We recommend that you implement the functions in the following order: initBigNum(), showBigNum() (possibly inserting some data manually into the digits array), scanBigNum(), addBigNums (). Altogether, it will require around 50 lines of C code. Once the program is working, you should be able to do things like: $ ./add 1000000000 42 Sum of 1000000000 and 42 is 1000000042 $ ./add 987654321987654321987654321 98765987659876598765 Sum of 987654321987654321987654321 and 98765987659876598765 is 987654420753641981864253086 BigNum.c x test1.c x 1 // BigNum.h ... LARGE positive integer values 3 #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started