C Programming Code Examples C > Recursion Code Examples C Program to Solve Tower-of-Hanoi Problem using Recursion C Program to Solve Tower-of-Hanoi Problem using Recursion This C Program uses recursive function & solves the tower of hanoi. The tower of hanoi is a mathematical puzzle. It consists of threerods, and a number of disks of different sizes which can slideonto 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. #include <stdio.h> void towers(int, char, char, char); int main() { int j; printf("Enter the number of disks : "); scanf("%d", &j); printf("The sequence of moves involved in the Tower of Hanoi are :\n"); towers(j, 'A', 'C', 'B'); return 0; } void towers(int j, char frompeg, char topeg, char auxpeg) { if (j == 1) { printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg); return; } towers(j - 1, frompeg, auxpeg, topeg); printf("\n Move disk %d from peg %c to peg %c", j, frompeg, topeg); towers(j - 1, auxpeg, topeg, frompeg); }