C PROGRAMMINGDATA STRUCTURES

Tower of Hanoi

Tower of Hanoi

 

#include <stdio.h>
void move(int n,char source, char target, char spare)
{
if (n==1)
printf("Move from %c to %cn",source,target);
else
{
move(n-1,source,spare,target);
move(1,source,target,spare);
move(n-1,spare,target,source);
}
}


void main()
{
int n;
printf("Enter a the number of rings: n");
scanf("%d", &n);
move(n,'A','C','B');
getch();
}

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button