i have to get 2 numbers (each of length 20 digits) from user and have add them and display the result (using arrays) . i have no idea how to add such a long digit number...please tell me how can i add both numbers.

your quick response will be highly appreciated. Thanks

6 Years
Discussion Span
Last Post by JyotiArora

You may want to start with a loop, to take in the digits. Make sure you have a way to ensure that, when added, if a digit exceeds 10, it gets added to the higher digit.

Also, remember that arrays begin with [0] and not [1], when you're programming the loop.

Edited by Red Goose: n/a

Start at the end of each array (ones digit).
Add the two values.
If < 10, store in the last entry of the answer array
If >=10, store (val MOD 10) instead
         save (val / 10) to add to the next digits
Move to the 10's digit and repeat

Hey in java, u will need to accept input in character form then convert it to string n then only u can convert 20 digit no to integer. there is no direct way 2 accept such long no.

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.