#include< stdio.h> #include< stdlib.h> /* n: number of disks used D: Start location A: arrival location I: middle location */ void toursHanoi(int n, char D, char A, char I) { if (n == 1) printf("Disk 1 from %c to %c \n" , D , A); else { // D to A toursHanoi(n - 1, D, I, A); printf("Disk %d from %c to %c \n", n , D ,A); //I to A toursHanoi(n - 1, I, A, D); } } main() { int nDisks = 3; toursHanoi(nDiscs, 'A', 'B', 'C'); system("pause"); }
Advertisement
AdBlock Detected
Please disable your ad blocker and refresh the window to use this website.