Answer to Question #44396 in C for vijayasurya

Question #44396
Towers of Hanoi (Recurssion)? This is the Program. (I have understood how the game works, but not able to understand and trace out the PROGRAM for it.) #include<stdio.h> #include<conio.h> void towers(int n, char source, char dest, char aux); void main() { int n; clrscr(); printf("\n Enter the number of disks:"); scanf("%d",&n); towers(n,'A','C','B'); } void towers(int n, char source, char dest, char aux) { if(n==1) { printf("\n Move Disk 1 from peg %c to peg %c",source,dest); return; } towers(n-1,source,aux,dest); printf("\n Move dist %d from peg %c to peg %c\n",n,source,dest); towers(n-1,aux,dest,source); } Please explain how i should trace the program. Also why is the return statement required inside the IF condition? (If i dont give it, it gives me error.) .
1
Expert's answer
2014-07-24T08:48:34-0400
The answer to the question is available in the PDF file https://www.assignmentexpert.com/homework-answers/programming-answer-44396.pdf

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal