Recursion

 

/*
TowerOfHanoi
*/
#include<stdio.h>
#include<conio.h>
void towerOfHanoi(int,char,char,char);
void main(){
	int noOfDisks;
	clrscr();
	printf("Enter the no of disks...");
	scanf("%d",&noOfDisks);
	printf("\nLet A,B and C be the three rods we are using Tower of Hanoi");
	towerOfHanoi(noOfDisks,'A','C','B');
	getch();
}

void towerOfHanoi(int noOfDisks,char from,char to,char aux){
	if(noOfDisks==1){
		printf("\nDisk 1: %c --> %c",from,to);
		return;
	}
	towerOfHanoi(noOfDisks-1,from,aux,to);
	printf("\nDisk %d: %c --> %c",noOfDisks,from,to);
	towerOfHanoi(noOfDisks-1,aux,to,from);
}