I think the following algorithm should work too. It is easier to implement as well.
i) Divide the given nos into three parts HEAD MID TAIL ii) Add 1 to number HEAD MID (in case of carry, follow basic addition rules) iii) reverse the new HEAD(store it in HEAD_REV) iv) required ans is:- 'new HEAD' MID HEAD_REV
Hope the following example helps to better understand algo
let nos: - 23469 9 12367
So HEAD -> 23469 MID -> 9 TAIL --> 12367 step 2:- 23469 9 +1 = 23470 0 (now HEAD -> 23470 MID -> 0 HEAD_REV -> 07432 )
Ans required: -
23470 0 07432
Plz do infrom me if there is a flaw in this procedure
koolkeshaw
source share