mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
28 lines
499 B
C
28 lines
499 B
C
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
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;
|
||
|
|
||
|
}
|