Friday, August 28, 2009

Towers of Hanoi



#include<stdio.h>



#include<conio.h>



main()



{



char
ans;








do



{




int n;




void move(int
n,char f,char
s,char t);








clrscr();









printf("\n\n\t\t\t TOWERS OF

HANOI
"
);




printf("\n\t\t\t******************");









printf("\nEnter the number of disks : ->");




scanf("%d",&n);









move(n,'f','s','t');









printf("\n\n DO U CONTINUE (Y/N)
:->"
);




scanf("%s",ans);



}









while(ans=='y'
|| ans=='Y');




getch();



}




void move(int
n,char f,char
s,char t)



{




if(n>0)




{




move(n-1,f,t,s);




printf("\n MOVE DISK %d FROM %c TO
%c"
,n,f,s);




move(n-1,t,s,f);




}



}





No comments:

Post a Comment