Tower of Hanoi | Write a recursive code in the C language Tower of Hanoi

Tower of Hanoi

Program for a tower of Hanoi

 
 
 
 
 
 
 
 
#include<stdio.h>
#include<conio.h>
 
void main()
 
{
clrscr();
int n;
char A = ‘A’ , B = ‘B’ , C = ‘C’ ;
void hanoi (int,char,char,char)
printf(“Enter the no. of disks:”);
scanf(“%d”,&n);
printf(“nn Tower of Hanoi problem with %d disksn”,n);
printf(“Sequence:n”);
 hanoi(n,A,B,C);
 
        printf(“n”);
           getch();
 
}
void hanoi(int n, char A, char B, char C)
   {
    If(n!=0)
    {
     hanoi(n-1, A, C, B);
     printf(“Move disk %d from %c to %cn,n, A,C”);
     hanoi(n-1, B, A , C);
     }
     }

C Program to Solve Tower-of-Hanoi Problem using Recursion

Leave a Comment

error: Content is protected !!