TOWER OF HANOI SOURCE CODE (DATA STRUCTURE WITH C)
/ * C program for Tower of Hanoi using Recursion */
#include <stdio.h>
void towers(int, char, char, char);
int main()
{
int num;
printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :\n");
towers(num, 'A', 'C', 'B');
return 0;
}
void towers(int num, char frompeg, char topeg, char auxpeg)
{
if (num == 1)
{
printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg);
return;
}
towers(num - 1, frompeg, auxpeg, topeg);
printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
towers(num - 1, auxpeg, topeg, frompeg);
//COPY FROM sbexam.blogspot.com
}
Hello!!
I gave you an up-vote.
Please follow me if you like and we can share posts and up-votes and help build our profiles.
thank you i will.if you share this post on you social media platform i also do the same.
Ok !! Thank you for your Upvote. lets grow together.