-
-
Save hoctructuyencntt/8f194c9c43a42f886643e4070b1e6bf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
void HANOI(int n, char coc_ban_dau, char coc_dich, char coc_trung_gian) | |
{ | |
if (n == 0) | |
{ | |
return; | |
} | |
HANOI(n - 1, coc_ban_dau, coc_trung_gian, coc_dich); | |
printf("Di chuyển đĩa %d từ cọc %c đến cọc %c\n", n, coc_ban_dau, coc_dich); | |
HANOI(n - 1, coc_trung_gian, coc_dich, coc_ban_dau); | |
} | |
int main() | |
{ | |
int n; | |
scanf("%d\n", &n); | |
HANOI(n, 'A', 'C', 'B'); // A, B và C là tên các cọc | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment