Aim: Write a program to implement Tower of Honio.
#include<stdio.h>
#include<conio.h>
#void towers(int num,char frompeg, char topeg,char auxpeg);
int main(){
int num;
printf("Enter the number of disks:");
scanf("%d",&num);
printf("The sequence of moves involved in the tower of Honio are \n:");
towers(num,'A','C','B');
return 0;
}
void towers(int num,char frompeg,char topeg,char auxpeg){
if(num==1){
printf("Move disk 1 from peg %c to peg %c \n",frompeg,topeg);
return 0;
}
towers(num-1,frompeg,auxpeg,topeg);
printf("Move disk %d from peg %c \n",num,frompeg,topeg);
towers(num-1,auxpeg,topeg,frompeg);
}
Leave a Reply