figure tower of hanoi figure move rings from to figure move ring from to figure move ring from to look at fig which shows three rings mounted on pole the problem is to move all these rings from pole to pole while maintaining the same order the main issue is that the smaller disk must always come above the larger disk we will be doing this using spare pole in our casea is the source polec is the destination poleand is the spare pole to transfer all the three rings from to cwe will first shift the upper two rings ( - ringsfrom the source pole to the spare pole we move the first two rings from pole to as shown in fig now that - rings have been removed from pole athe nth ring can be easily moved from the source pole (ato the destination pole (cfigure shows this step the final step is to move the - rings from the spare pole (bto the destination pole (cthis is shown in fig to summarizethe solution to our problem of moving rings from to using as spare can be given asbase caseif = move the ring from to using as spare recursive casemove rings from to using as spare move the one ring left on to using as spare move rings from to using as spare the following code implements the solution of the tower of hanoi problem #include int main(int nprintf("\ enter the number of rings")scanf("% "& )move( ,' '' '' ')return void move(int nchar sourcechar destchar spareif ( == printf("\ move from % to % ",source,dest)else move( - ,source,spare,dest)move( ,source,dest,spare)move( - ,spare,dest,source)let us look at the tower of hanoi problem in detail using the program given above figure on the next page explains the working of the program using onethen twoand finally three rings recursion versus iteration recursion is more of top-down approach to problem solving in which the original problem is divided into smaller sub-problems on the contraryiteration follows bottom-up approach that begins with what is known and then constructing the solution step by step recursion is an excellent way of solving complex problems especially when the problem can be defined in recursive terms for such problemsa recursive code can be written and modified in much simpler and clearer manner