Your SlideShare is downloading. ×
Tower of hanoi
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Tower of hanoi

106

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
106
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. /* * C program for Tower of Hanoi using Recursion */ #include <stdio.h> #include<conio.h> void towers(int, char, char, char); main() { int num; printf("Enter the number of disks : "); scanf("%d", &num); printf("The sequence of moves involved in the Tower of Hanoi are :n"); towers(num, 'A', 'C', 'B'); return 0; } void towers(int num, char begpeg, char auxpeg, char endpeg) { if (num == 1) { printf("nmove disk 1 from peg %c to peg %c",begpeg,auxpeg); return; } towers(num - 1, begpeg, endpeg, auxpeg); printf("n Move disk %d from peg %c to peg %c", num, begpeg, auxpeg); towers(num - 1, endpeg, auxpeg, begpeg); getch(); }

×