nguyenhappy92

Bài Toán Tháp Hà Nôi

Oct 5th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. // Thap Ha Noi
  2. #include<stdio.h>
  3. #include<conio.h>
  4.  
  5. void Move(int n, int x,int y)// Chuyen n dia tu cot x sang cot y
  6. {
  7. if(n==1)
  8. printf("\n Di chuyen 1 dia tu %d sang %d", x, y);
  9. else
  10. {
  11. // Chuyen n-1 dia tu cot x sang cot trung gian (x+y+z=6)
  12. Move(n-1,x,6-x-y);
  13. // Chuyen 1 dia tu cot x sang cot y
  14. Move(1,x,y);
  15. // Chuyen n-1 dia tu cot trung gian sang cot y
  16. Move (n-1,6-x-y,y);
  17. }
  18. }
  19. void main()
  20. {
  21. int n;
  22. printf("\n Nhap so dia: ");
  23. scanf("%d",&n);
  24. int x=1,y=2;
  25. Move(n,x,y);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment