#include#include #include 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( ); } Output: Enter the number of disks you want to play with: 3 The No of moves required is=7 Move Disk from A to C Move Disk from A to B Move Disk from C to B Move Disk from A to C Move Disk from B to A Move Disk from B to C Move Disk from A to C
C Programming,C Objective,Advanced C/C++ Programming,C++ Programming,Linux System Programming,RTOS,Interview Questions,Multimedia,Stagefright,Android Application Programming
My Blog List
Write a C program for demonstrating Tower of Hanoi using Recursion
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment