-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain(4).c
More file actions
32 lines (31 loc) · 684 Bytes
/
main(4).c
File metadata and controls
32 lines (31 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
void hanoi(int m , char from , char help , char to)
{
if(m == 1)
printf("%c->%c\n",from,to);
else
{
hanoi(m - 1, from, to, help);
printf("%c->%c\n",from,to);
hanoi(m - 1, help, from, to);
}
}
void hanoikhas(int m , char from , char help , char to)
{
if(m == 2){
printf("%c->%c\n",from,to);
printf("%c->%c\n",help,to);}
else
{
hanoikhas(m - 2 , from , help , to);
hanoi(m - 2 , to , from , help);
printf("%c->%c\n",from,to);
hanoi(m - 1 , help , from , to);
}
}
int main() {
int m;
scanf("%d",&m);
hanoikhas(m , 'A','B','C');
return 0;
}