Implementing the usual pencil and paper addition algorithm


Discuss the below:

Q: Create a C++ program that reads in two positive integers that are 20 or fewer digits in length and outputs the sum of the two numbers.

Your program will read the digits as values of type char so that the number 1234 is read as four characters '1', '2', '3' and '4'. After they are read into the program, the characters are changed to values of type int. The digits will be read into a partially filled array and you might find it useful to reverse the order of the elements in the array after array is filled with data from the keyboard.

Your program will perform the addition by implementing the usual pencil and paper addition algorithm. The result of the addition is stored in an array of size 20 and the result is written to screen. if the result of the addition is an integer with more
than maximum number of digits(that is more than 20 digits) then your program should issue a message saying that it has encountered "integer overflow".

You must be able to change the maximum length of the integers by changing only one globally defined constant. Include the loop that allows the user to continue to do more additions until the user says the program should end.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Implementing the usual pencil and paper addition algorithm
Reference No:- TGS01937097

Now Priced at $25 (50% Discount)

Recommended (95%)

Rated (4.7/5)