TOWER OF HANOI
10:31 AM
#include<stdio.h>
#include<conio.h>
#include<math.h>
int moves;
void transfer(int n,char from,char to,char temp);
int main(void)
{
int n;
printf("Enter the number:");
scanf("%d",&n);
transfer(n,'A','C','B');
moves=pow(2,n)-1;
printf("No.of moves=%d\n",moves);
getch();
}
void transfer(int n,char from,char to,char temp)
{
if(n>0)
{
transfer(n-1,from,temp,to);
printf("Move disk %d from %c to %c\n",n,from,to);
transfer(n-1,temp,to,from);
}
}
#include<conio.h>
#include<math.h>
int moves;
void transfer(int n,char from,char to,char temp);
int main(void)
{
int n;
printf("Enter the number:");
scanf("%d",&n);
transfer(n,'A','C','B');
moves=pow(2,n)-1;
printf("No.of moves=%d\n",moves);
getch();
}
void transfer(int n,char from,char to,char temp)
{
if(n>0)
{
transfer(n-1,from,temp,to);
printf("Move disk %d from %c to %c\n",n,from,to);
transfer(n-1,temp,to,from);
}
}
Great blog. All posts have something to learn. Your work is very good and i appreciate you and hopping for some more informative posts. Laptop Repair Prices in Amsterdam
ReplyDelete