Alx09

Turnurile din hanoi

May 18th, 2020
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.31 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. void h(int n, char a, char b, char c)
  5. {
  6.     if (n == 1) printf("%c %c\n", a, b);
  7.     else
  8.     {
  9.         h(n - 1, a, c, b);
  10.         printf("%c %c\n", a, b);
  11.         h(n - 1, c, b, a);
  12.     }
  13. }
  14. int main()
  15. {
  16.     unsigned n;
  17.     printf("n= "); scanf("%u", &n);
  18.     h(n, 'a', 'b', 'c');
  19.    
  20.    
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment