Skip to content
Open

toh #83

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Towers of Hanoi/TOH.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>
#include<conio.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header file is not required.

#include<string.h>
void TOH(int n,char s,char d,char i)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOH can be renamed to something more verbose.

{
if(n==1)
{
printf("Move %d from %c to %c\n",n,s,d);
}
else
{
TOH(n-1,s,i,d);
printf("Move %d from %c to %c\n",n,s,d);
TOH(n-1,i,d,s);
}
}
void main()
{
int n;
printf("Enter the number of discs:\n");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use std::cout and std::cin instead of printf and scanf.

scanf("%d",&n);
TOH(n,'s','d','i');

}