mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
Merge pull request #66 from AnupKumarPanwar/master
Moved TowerOfHanoi.c to misc
This commit is contained in:
commit
f65f65a617
@ -1,29 +1,29 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// Function for Tower of Hanoi algorithm
|
// Function for Tower of Hanoi algorithm
|
||||||
void hanoi(int noOfDisks,char where,char to,char extra){
|
void hanoi(int noOfDisks,char where,char to,char extra){
|
||||||
if(noOfDisks == 0 )
|
if(noOfDisks == 0 )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hanoi(noOfDisks-1, where, extra , to);
|
hanoi(noOfDisks-1, where, extra , to);
|
||||||
printf("Move disk : %d from %c to %c\n",noOfDisks,where,to);
|
printf("Move disk : %d from %c to %c\n",noOfDisks,where,to);
|
||||||
hanoi(noOfDisks-1,extra,to,where);
|
hanoi(noOfDisks-1,extra,to,where);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int main(void){
|
int main(void){
|
||||||
int noOfDisks;
|
int noOfDisks;
|
||||||
|
|
||||||
//Asks the number of disks in the tower
|
//Asks the number of disks in the tower
|
||||||
printf("Number of disks: \n");
|
printf("Number of disks: \n");
|
||||||
scanf("%d", &noOfDisks);
|
scanf("%d", &noOfDisks);
|
||||||
|
|
||||||
hanoi(noOfDisks,'A','B','C');
|
hanoi(noOfDisks,'A','B','C');
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user