Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tower_of_hanoi.c #430

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions C/tower_of_hanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// you got 3 pillars(a,b,c) , first one fully filled and we need to move a to c , we can get the help of b also.
// rules: 1. only one disk at a time. 2. disk's can only be placed on pillars only

#include <stdio.h>

void TOH (int n, int A, int B, int C){
if ( n > 0 ){
TOH (n-1, A, C, B);
printf("(%d , %d)\n",A,C);
TOH (n-1, B, A, C);
}
}

int main(){
TOH(16, 1, 2, 3);
return 0;
}