Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribed

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 4 #include 5 #include 6 #include 7 #include 8 #include "BigNum.h" 10 // Initialise a BigNum to N bytes, all zero 11 void initBigNum(BigNum *n, int Nbytes) 12 { 13 // TODO 14 return; 15 16 17 // Add two BigNums and store result in a third BigNum 18 void addBigNums (BigNum n, BigNumm, BigNum *res) 19 { 20 // TODO 21 return; 22 } 23 24 // Set the value of a BigNum from a string of digits 25 // Returns 1 if it *was* a string of digits, otherwise 26 int scanBigNum( char *s, BigNum *n) 27 { 28 // TODO 29 return 1; 30} 31 32 // Display a BigNum in decimal format 33 void showBigNum(BigNum n) |34 { 35 // TODO 36} 37 38 void freeBigNum(BigNum n) { 39 // TODO 40 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions