Skip to content
DATA STRUCTURE
DATA STRUCTURE

Learn everything about Data structures.

  • Algorithms
  • DSA
  • Array
  • Stack
  • Queue
  • Matrix
  • Programs
DATA STRUCTURE

Learn everything about Data structures.

Tower of Hanoi Recursive program in C Programming

YASH PAL, February 26, 2023May 28, 2024

In this tutorial post, we will write a Tower of Hanoi Recursive program in the c programming language in which the user will enter the number of disks.

#include<stdio.h>
#include<conio.h>

void tower(int, char, char, char);

void main()
{
    int n;
    clrscr();
    printf("Enter how many disks");
    scanf("%d",&n);
    tower(n,'A','B','C');
    getch();
}

void tower(int n, char beg, char aux, char end)
{
    if(n == 1)
    {
        printf("Disk 1 is transfered from %c to %c\n",beg,end);
        return;
    }

    tower(n-1,beg,end,aux);
    printf("Disk %d is transferred from %c to %c\n",n,beg,end);
    tower(n-1,aux,beg,end);
}
data structures Programs stack DSAprogramsstack

Post navigation

Previous post
Next post
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • About US
  • Contact US
  • Data Structures and algorithms tutorials
  • Digital Communication Tutorials
  • DMCA
  • HackerRank All Algorithms problems solutions
  • HackerRank C problems solutions
  • HackerRank C++ problems solutions
  • HackerRank Java solutions
  • HackerRank Python solutions
  • Human Values Tutorials
  • Internet of Things Tutorials
  • Privacy Policy
©2025 DATA STRUCTURE | WordPress Theme by SuperbThemes