Saturday 15 March 2014

Write a program of hanoi tower.

Write a program of hanoi tower.

Code for Program of hanoi tower in C Programming

#include<stdio.h>
#include<conio.h>

void main()
{
  int n;
  int hanoi(int,char,char,char);
  clrscr();
  printf("Enter  the no of disk:");
  scanf("%d",&n);
  hanoi(n,'a','b','c');
  getch();
}
int hanoi(int n,char a, char b, char c)
{
while(n!=0)
{
hanoi(n-1,a,c,b);
printf("Moving disk %d from %c tower to %c tower\n",n,a,c);
hanoi(n-1,b,a,c);
break;
}
return 0;

}

No comments:

Post a Comment