mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
Moved TowerOfHanoi.c to misc
This commit is contained in:
parent
05f6b01569
commit
06da42e14f
@ -1,29 +1,29 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Function for Tower of Hanoi algorithm
|
||||
void hanoi(int noOfDisks,char where,char to,char extra){
|
||||
if(noOfDisks == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
hanoi(noOfDisks-1, where, extra , to);
|
||||
printf("Move disk : %d from %c to %c\n",noOfDisks,where,to);
|
||||
hanoi(noOfDisks-1,extra,to,where);
|
||||
}
|
||||
}
|
||||
int main(void){
|
||||
int noOfDisks;
|
||||
|
||||
//Asks the number of disks in the tower
|
||||
printf("Number of disks: \n");
|
||||
scanf("%d", &noOfDisks);
|
||||
|
||||
hanoi(noOfDisks,'A','B','C');
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Function for Tower of Hanoi algorithm
|
||||
void hanoi(int noOfDisks,char where,char to,char extra){
|
||||
if(noOfDisks == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
hanoi(noOfDisks-1, where, extra , to);
|
||||
printf("Move disk : %d from %c to %c\n",noOfDisks,where,to);
|
||||
hanoi(noOfDisks-1,extra,to,where);
|
||||
}
|
||||
}
|
||||
int main(void){
|
||||
int noOfDisks;
|
||||
|
||||
//Asks the number of disks in the tower
|
||||
printf("Number of disks: \n");
|
||||
scanf("%d", &noOfDisks);
|
||||
|
||||
hanoi(noOfDisks,'A','B','C');
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user