C program for tower of hanoi

Here is the C program for tower of hanoi:

#include<conio.h>
#include<stdio.h>
void transfers(int,char,char,char);
int main()
{
int n;
printf("enter how many tower:");
scanf("%d",&n);
transfers(n,'L','C','R');
getch();
}
void transfers(int n ,char from, char to, char temp)
{
if(n==0)
return;
else
transfers(n-1,from, temp, to);
printf("\n move %d from %c to %c",n,from,to);
transfers(n-1,temp, to,from);

}
Output

Other C Programming:


Powered by Blogger.