Wednesday, 9 November 2011

Simple game Tower of Hanoi for C languange

This is the second file...lol ^^
and it is more easy than the tic tac toe game....

enjoy and try it at your computer...^^8

#include <stdio.h>
#include <stdlib.h>

void main()
{
void hanoi(int n,char tower1,char tower3,char tower2);
char tower1='A',tower2='B',tower3='C';
int n;

printf("\n WELCOME TO TOWER OF HANOI SIMULATION\t\t\tby:Ridwan ^^v \n\n ");
printf("---------------------------------------------------\n");
printf("We'll help you to finish the tower of hanoi game only several second\n");
printf("Please Enjoy it\n");
printf("====================================================\n");

printf(" Enter the summary of disk on A : "); scanf("%d",&n);
puts("");
if(n<1)
{
printf(" Nothing to move. The disk must only or more than 1! ^^v \n");
}

hanoi(n, tower1, tower3, tower2);
getch();
}

void hanoi(int n,char tower1,char tower3,char tower2)
{

if(n==1)
{
printf(" Move the disk no 1 from %c to %c\n",tower1,tower3);
return;
}
else

hanoi(n-1,tower1,tower2,tower3);
printf(" Move the disk no %d from %c to %c\n",n,tower1,tower3);
hanoi(n-1,tower2,tower3,tower1);
}



more easy right? but it still confusing my head when I'm in the first year of college...lol ^^

No comments:

Post a Comment