# Implement Tower of Hanoi using C language

0
1069
This C programÂ uses recursive function & solves the tower of hanoi. The tower of hanoi is a mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top. We have to obtain the same stack on the third rod.
Here is the source code of the C program for solving towers of hanoi.
[message_box title=”PROGRAM” color=”yellow”]

#include<stdio.h>
void TOH(int num, char x, char y, char z);
int main() {
Â Â  int num;
Â Â  printf(“\nEnter number of plates:”);
Â Â  scanf(“%d”, &num);
Â Â  TOH(num 1, ‘A’, ‘B’, ‘C’);
Â Â  return (0);
}
void TOH(int num, char x, char y, char z) {
Â Â  if (num > 0) {
Â Â Â Â Â Â TOH(num 1, x, z, y);
Â Â Â Â Â Â printf(“\n%c -> %c”, x, y);
Â Â Â Â Â Â TOH(num 1, z, y, x);
Â Â  }
}
[/message_box]
Following Image will explain you more about tower of hanoi :
SHARE
Previous articleFunction in C language
Next articleHow to control GPIO with SCRATCH
I am third year student of computer engineering in L.D COLLEGE OF ENGINEERING,Ahmedabad.