Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,309 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 845 people online right now. Registration is fast and FREE... Join Now!




Tower of Hanoi in C with graphics

 
Reply to this topicStart new topic

Tower of Hanoi in C with graphics, Graphics implementation of the Tower of Hanoi problem

bryanski
12 Nov, 2008 - 12:47 AM
Post #1

New D.I.C Head
*

Joined: 12 Nov, 2008
Posts: 5

Hi. I have a code for the solution of the Tower of Hanoi but we are told to do the 2d graphics in C. Java would be okay but graphics in c is a bit difficult for me.

CODE

#include <conio.h>
#include <stdio.h>

main()
{
    void hanoi(char,char,char,int);
    char t1='A',t2='B',t3='C';
    int n;
    clrscr();
    printf("\n Enter the no. of disks on Tower A:");
     scanf("%d",&n);
    if(n<1)
    {
        printf("\n Nothing to move");
    }
    else
    hanoi(t1,t2,t3,n);
    getch();
    return 0;
}

void hanoi(char t1,char t2,char t3,int n)
{
    static int step=0;
    step++;
    if(n==1)
    {
        printf("\n Move top disk from Tower %c ----> %c",t1,t2);
        return;
     }
    hanoi(t1,t3,t2,n-1);
    printf("\n Move top disk from Tower %c ----> %c",t1,t2);
    hanoi(t3,t2,t1,n-1);
}


Actually the solution for the Tower of Hanoi also came here. Thanks for those who'll be helping...

Bryan

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 07:08PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month