|
Computer Whiz versus Math Genius! Christopher, a high school computer whiz kid, has been challenged by his cousin Thea, a math Genius, to compute for integers using the four basic arithmetic operations using a computer program. However, Thea, wanting his dear cousin to fail, deliberately increased the complexity on how it will be done. From her explanation, integers entered in the console by users should be temporarily stored into a variable and later copied to an array, digit by digit. She broadened the details by providing an illustration. Standard Addition Process Thea’s Addition Process Using Variables Using Arrays
She then added that the arithmetic operations, except division, must be done digit by digit in the array, starting from its last element progressing to the first, just like the normal way. Christopher was startled! He never expected a challenge like this. As his buddy, your task is to help him design and implement an algorithm that will perform the four (4) basic arithmetic operations, namely: addition, subtraction, multiplication, and division. To follow good programming standard, you both decided to have four (4) user-defined functions to complement the said operations. Here are the function prototypes: void add(int a1[], int a2[]); void subtract(int a1[], int a2[]); void multiply(int a1[], int a2[]); void divide(int a1[], int a2[]); Christopher also added that for clarity, it is a must to define a void-type function display(int result[]) in main() to display the elements of any array passed to it. Sample Input/Output: Type 2 integers separated by a space: 123 59 [1] Add [2] Subtract [3] Multiply [4] Divide Please choose operation -> 1 123 + 59 is 182 Try Again? [y/n] -> y Type 2 integers separated by a space: 123 59 [1] Add [2] Subtract [3] Multiply [4] Divide Please choose operation -> 6 Error: Input not recognized! Try Again? [y/n] -> n Bye!
|