how can i write a subtraction method base on this add method?Code:/* * used to add two numbers with the same sign * GIVEN FOR GUIDANCE */ int* add(int* input1, int* input2, int base) { int len1 = bignum_length(input1); //get length of first input int len2 = bignum_length(input2); //get length of second input int resultlength = ((len1 > len2)? len1 : len2) + 2; //if len1 > len2, return len1, if len2 > len1, return len 2. Then add 2 to the result int* result = (int*) malloc (sizeof(int) * resultlength); //allocate a memeory address of the size of int x resultlength int r = 0; //index int carry = 0; //carry over int sign = input1[len1]; //last element of input1, which is -1 int num1, num2; len1--; len2--; while (len1 >= 0 || len2 >= 0) { if (len1 >= 0) { num1 = input1[len1]; } else { num1 = 0; } if (len2 >= 0) { num2 = input2[len2]; } else { num2 = 0; } result[r] = (num1 + num2 + carry) % base; carry = (num1 + num2 + carry) / base; len1--; len2--; r++; } if (carry > 0) { result[r] = carry; r++; } result[r] = sign; reverse(result); return result; }
or can someone explain what each line of this method code do?