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
#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:
C programming beginner from Hello World
Keywords in C programming
Program for Stack Using switch( PUSH POP DISPLAY and empty
Queue Implementation
Matrix Row sum , column sum and transpose
Program that uses pointers to copy an array of double
Break and continue statement
C program for tower of hanoi
Infix into postfix
Keywords in C programming
Program for Stack Using switch( PUSH POP DISPLAY and empty
Queue Implementation
Matrix Row sum , column sum and transpose
Program that uses pointers to copy an array of double
Break and continue statement
C program for tower of hanoi
Infix into postfix
Post a Comment