Tower of Hanoi problem code in C Language
Write a c program for Tower of Hanoi problem. User has to provide input to the program in terms of numbers of disc on each tower and the program should print the solution of tower of hanoi.
Tower of Hanoi code
#include #include #include #include void toh(int n,char src,char dest,char by) { time_t t1; if(n==1) printf("Move frm %c to %c \n",src,dest); else { toh(n-1,src,by,dest); printf("Move frm %c to %c time: \n ",src,dest); delay(500); toh(n-1,by,dest,src); } //printf("time:%ld\n",stime(NULL)); } void main() { clrscr(); printf("Enter the no of disks\n"); int n; scanf("%d",&n); time_t t1,t2; t1=time(NULL); toh(n,'A','C','B'); t2=time(NULL); printf("The difference is: %f seconds\n",difftime(t2,t1)); getch(); }
Leave a Reply