CODE FOR TOWER OF HANOI

#include<stdio.h>
#include<conio.h>
void hanoi(int n,char s,char m,char d);
void main()
{
 int n;
 char s='a',d='c',m='b';
 clrscr();
 printf("enter number of disc :");
 scanf("%d",&n);
 hanoi(n,s,m,d);
 getch();
}
void hanoi(int n,char s,char m,char d)
{
  if(n!=0)
  {
   hanoi(n-1,s,d,m);
   printf("Move %d from %c to %c\n",n,s,d);
   hanoi(n-1,m,s,d);
  }
}




Comments

Popular posts from this blog

Code for BUBBLE Sort

Code for Circular Linked List c-programing

Code for SELECTION Sort in C-Programming