Add files via upload

This commit is contained in:
suraj 2023-04-02 13:46:53 +05:30 committed by GitHub
parent 5f297e7f9b
commit 0a576f455e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

20
code-files/toh.c Normal file
View File

@ -0,0 +1,20 @@
//C program for towers of hanoi problem
#include<stdio.h>
void toh(int n,char s[],char d[],char a[]);
int main(void) {
char s[]="source",d[]="destination",a[]="auxiliary";
int n;
printf("Enter the number of disks: ");
scanf("%d",&n);
toh(n,s,d,a);
return 0;
}
void toh(int n,char s[],char d[],char a[]) {
static int step;
if(n==1) printf("step %d:move disk %d from %s to %s\n",++step,n,s,d);
else {
toh(n-1,s,a,d);
printf("step %d:move disk %d from %s to %s\n",++step,n,s,d);
toh(n-1,a,d,s);
}
}