#include<stdio.h>
#include<conio.h>
#include<math.h>
void hanoi(int x, char from,char to,char aux)
{
if(x==1)
{
printf("Move Disk From %c to %c\n",from,to);
}
else
{
hanoi(x-1,from,aux,to);
printf("Move Disk From %c to %c\n",from,to);
hanoi(x-1,aux,to,from);
}
}
void main()
{
int disk;
int moves;
clrscr();
printf("Enter the number of disks you want to play with:");
scanf("%d",&disk);
moves=pow(2,disk)-1;
printf("\nThe No of moves required is=%d \n",moves);
hanoi(disk,'A','C','B');
getch();
}
Chinjoo
0
Newbie Poster
Recommended Answers
Jump to PostPlease stop posting poorly formated non-standard code for no reason at all. If you insist on spamming the forum with pointless threads, I'll delete them without hesitation.
Jump to PostIf you are so inclined to contribute fully-working code snippets, they would be most appreciated in our code snippet library @ www.daniweb.com/code/ - not the forums.
Thanks!
All 5 Replies
Narue
5,707
Bad Cop
Team Colleague
Dani
3,875
The Queen of DaniWeb
Administrator
Featured Poster
Premium Member
raftinga
0
Newbie Poster
ajay.krish123
-4
Junior Poster in Training
yash00yash
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.