Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q4 in c-programming: C) Grades for Michael Rus! XY Course Home xy D Homework-06-

ID: 3722735 • Letter: Q

Question

Q4 in c-programming:

C) Grades for Michael Rus! XY Course Home xy D Homework-06-Spring-2c xee replit-RaggedDirtyPlan x.eChegg Study I Guided S/X C E ESPN. The World file://home/chronos/u 098f0a422b194aa432f0e5b77b6868e769e8f3ab/Downloads Homework-06-Spring-2018 pdf comings o net M IMDb Movies TV a YouTube Moles Mov eTrai a Amazon.com 0 lin Wells argo Person w meto Face Capital One redit C Q4: (Towers of Hanoi) (Bonus 10 points) Every budding computer scientist must grapple with certain classic problems, and the Towers of Hanoi (see picture) is one of the most famous of these. Legend has it that in a temple in the Far East, priests are attempting to move a stack of disks from one peg to another. The initial stack had 64 disks threaded onto one peg and arranged from bottom to top by decreasing size. The priests are attempting to move the stack from this peg to a second peg under the constraints that exactly one disk is moved at a time, and at no time may a larger disk be placed above a smaller disk. A third peg is available for temporarily holding the disks. Supposedly the world will end when the priests complete their task, so there's little incentive for us to facilitate their efforts Let's assume that the priests are attempting to move the disks from peg 1 to peg 3. We wish to develop an algorithm that will print the precise sequence of disk-to-disk peg transfers. If we were to approach this problem with conventional methods, we'd rapidly find ourselves hopelessly knotted up in managing the disks. Instead, if we attack the problem with recursion in mind, it

Explanation / Answer

#include <stdio.h>

#include <conio.h>

void hanoi(char,char,char,int);

void main()

{

int num;

clrscr();

printf(" ENTER NUMBER OF DISKS: ");

scanf("%d",&num);

printf(" TOWER OF HANOI FOR %d NUMBER OF DISKS: ", num);

hanoi('A','B','C',num);

getch();

}

void hanoi(char from,char to,char other,int n)

{

if(n<=0)

printf(" ILLEGAL NUMBER OF DISKS");

if(n==1)

printf(" MOVE DISK FROM %c TO %c",from,other);

if(n>1)

{

hanoi(from,other,to,n-1);

hanoi(from,to,other,1);

hanoi(to,from,other,n-1);

}

}