hanoi tower game

amatallah 0 Tallied Votes 172 Views Share

function to solve hanoi tower game

#include<stdio.h>
/*************************************************************************/
void towers(int n,char frompeg,char topeg,char auxpeg)
{
	if(n==1)
	{
	printf("\n%s%c%s%c","move disk 1 from peg ",frompeg," to peg ",topeg);
	return;
	}

	towers(n-1,frompeg,auxpeg,topeg);
	printf("\n%s%d%s%c%s%c","move disk ",n," from peg ",frompeg,
	"to peg",topeg);
	towers(n-1,auxpeg,topeg,frompeg);
}
/************************************************************************/
void main()
{
	int n;
	scanf("%d",&n);
	towers(n,'A','B','C');
}
amatallah 0 Newbie Poster

where are u ppl :sad: :sad:

Micko 2 Junior Poster

Interesting, please try to stick to the Standard.
It's int main (void), not void main()

Jodie Rodger -4 Unverified User

;) :idea: :rolleyes: :surprised :cool: :twisted: :p :?: :cheesy: :mrgreen: :) :!: :confused: :lol: :eek: :-| :mad: :sad: THATS MY COMMENT

Salem commented: Twit -4
manutd 2 Junior Poster

Is this C++ code? It looks like C code.

sharma tiptur -4 Newbie Poster

can this be done without recursion

Salem commented: ToH has three pegs, your post is 3 YEARS too late - coincidence? -4
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster

>>can this be done without recursion

Most likely, yes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.