This post related about c programming.
This program is towers of Hanoi game let's enjoy.
Click to play 👆👆👆👆👆👆
Program:-
Output:
Enter no of disks
4
Move disk 1 from A to B
Move disk 2 from A to C
Move disk 1 from B to C
Move disk 3 from A to B
Move disk 1 from C to A
Move disk 2 from C to B
Move disk 1 from A to B
Move disk 4 from A to C
Move disk 1 from B to C
Move disk 2 from B to A
Move disk 1 from C to A
Move disk 3 from B to C
Move disk 1 from A to B
Move disk 2 from A to C
Move disk 1 from B to CExplanation:
//Coming Soon..
This program is towers of Hanoi game let's enjoy.
Click to play 👆👆👆👆👆👆
Program:-
#include <stdio.h> void towerOfHanoi(int,char,char,char); main() { int n; printf("Enter no of disks\n"); scanf("%d",&n); towerOfHanoi(n, 'A', 'C', 'B'); } void towerOfHanoi(int n, char from, char to, char temp) { if (n == 1) { printf("Move disk 1 from %c to %c\n", from, to); return; } towerOfHanoi(n-1, from, temp, to); printf("Move disk %d from %c to %c\n", n, from, to); towerOfHanoi(n-1, temp, to, from); }
Enter no of disks
4
Move disk 1 from A to B
Move disk 2 from A to C
Move disk 1 from B to C
Move disk 3 from A to B
Move disk 1 from C to A
Move disk 2 from C to B
Move disk 1 from A to B
Move disk 4 from A to C
Move disk 1 from B to C
Move disk 2 from B to A
Move disk 1 from C to A
Move disk 3 from B to C
Move disk 1 from A to B
Move disk 2 from A to C
Move disk 1 from B to CExplanation:
//Coming Soon..
No comments:
Post a Comment