NEP -DATA STRUCTURE

PART-A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

PART-B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

4. Write a C Program to implement Towers of Hanoi

 
  
 
 
 
 
 
/*Write a C Program to implement Towers of Hanoi.*/

#include 
#include 
void hanoi(char,char,char,int);
void main()
{
	int num;
	clrscr();
	printf("\nENTER NUMBER OF DISKS: ");
	scanf("%d",&num);
	printf("\nTOWER OF HANOI FOR %d NUMBER OF DISKS:\n", num);
	hanoi('A','B','C',num);
	getch();
}
void hanoi(char from,char to,char other,int n)
{
	if(n<=0)
		printf("\nILLEGAL NUMBER OF DISKS");
	if(n==1)
		printf("\nMOVE DISK FROM %c TO %c",from,other);
	if(n>1)
	{
		hanoi(from,other,to,n-1);
		hanoi(from,to,other,1);
		hanoi(to,from,other,n-1);
	}
}