Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfff9173

Browse files
authored
Merge pull request#73 from AnamikaSamanta/main
Tower of Hanoi using C
2 parents0d0a6ab +a52b699 commitfff9173

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎TOWER.CPP‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Towers of Hanoi problem using recursion*/
2+
/* Data Structures Using C by UDIT AGARWAL*/
3+
4+
#include<stdio.h>
5+
#include<conio.h>
6+
voidmain()
7+
{
8+
clrscr();
9+
int n;
10+
char A='A',B='B',C='C';
11+
voidhanoi(int,char,char,char);
12+
printf ("Enter Number of Disks:");
13+
scanf("%d",&n);
14+
printf("\n\n Tower of Hanoi problem with %d disks\n",n);
15+
printf("Sequence is :\n");
16+
hanoi (n, A, B, C);
17+
printf ("\n");
18+
getch();
19+
}
20+
voidhanoi(int n,char A,char B,char C)
21+
{
22+
if (n!=0)
23+
{
24+
hanoi (n-1,A,C,B);
25+
printf ("Move disk %d from %c to %c\n",n,A,C);
26+
hanoi (n-1,B,A,C);
27+
}
28+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp