Towor of Honoi exp 1 In ADS
unknown
plain_text
a year ago
547 B
14
Indexable
#include<stdio.h>
int static count = 0;
void TOH(int n, int A, int B, int C){
//base case
if(n == 0){
return;
}else if(n ==1){
printf("Move Disk from %d to %d \n",A,C);
count++;
}else{
TOH(n-1,A,C,B);
printf("Move Disk from %d to %d \n",A,C);
count++;
TOH(n-1,B,A,C);
}
}
int main(){
int n;
printf("Enter the number of disc :");
scanf("%d",&n);
TOH(n,1,2,3);
printf("Total number of Moves : %d",count);
return 0;
}
Editor is loading...
Leave a Comment