24 votes 24 votes The following recursive function in C is a solution to the Towers of Hanoi problem. void move(int n, char A, char B, char C) { if (......................) { move (.............................); printf("Move disk %d from pole %c to pole %c\n", n, A, C); move (.....................); } } Fill in the dotted parts of the solution. Programming in C gatecse-2002 programming recursion descriptive + – Kathleen asked Sep 15, 2014 recategorized Jun 30, 2017 by Silpa Kathleen 3.2k views answer comment Share Follow See 1 comment See all 1 1 comment reply Bhagirathi commented Sep 18, 2014 reply Follow Share If(n==1) { Printf("\n %s %c %s %c","move disk1 from pole",A,"to pole",B); Return; } Towers(n-1,A,C,B); Printf.... Towers(n-1,C,B,A); 2 votes 2 votes Please log in or register to add a comment.
Best answer 29 votes 29 votes void move(int n, char A, char B, char C) { if (n > 0) { move (n-1, A, C, B); printf("Move disk %d from pole %c to pole %c\n", n, A, C); move (n-1, B, A, C); } } minal answered Sep 7, 2015 edited Dec 28, 2015 by Arjun minal comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments Riya Roy(Arayana) commented Dec 28, 2015 reply Follow Share yes 1 votes 1 votes bahirNaik commented Dec 29, 2015 reply Follow Share Yes it is correct !! 1 votes 1 votes srestha commented Oct 27, 2017 reply Follow Share need updation of this ans https://gateoverflow.in/163078/tower-of-hanoi?state=comment-163092&show=163092#c163092 2 votes 2 votes Please log in or register to add a comment.
7 votes 7 votes If(n==1) { Printf("\n %s %c %s %c","move disk1 from pole",A,"to pole",B); Return; } Towers(n-1,A,C,B); Printf.... Towers(n-1,C,B,A); Bhagirathi answered Sep 18, 2014 Bhagirathi comment Share Follow See all 0 reply Please log in or register to add a comment.