SET OF PROGRAMS

This blog provided "C" programs for beginners. Providing c programs for students.enjoy this blog.this blog include many c programs for engineering students, IT engineering students and programmers this blog is very useful.this blog post daily 1-5 programs for you.this programs use full for devlop games devlops application and much more. This blog programs useful for projects because all programs post with explanations.

Search Bar

Ads Here

Thursday, 28 June 2018

C program for towers of Hanoi game

This post related about c programming.
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);
}
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 C
Explanation:
//Coming Soon..

No comments:

Post a Comment