bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc051.c (1046B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 08 Feb 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Tower of Hanoi: Write a program to print out the sequence in which 4 disks should be moved from peg A to peg C using peg B.
      9 */
     10 /* Let Us C, Chap- 10 (Recursive), Qn No.: B(c) */
     11 /* This file is auto-generated by a bot. */
     12 /* This code is not compiled; it is for reference only. */
     13 
     14 
     15 #include <stdio.h>
     16 #include <math.h>
     17 #include <stdlib.h>
     18 
     19 void hanoi(int, char, char, char);
     20 
     21 int main()
     22 {
     23     int n = 4; 
     24 
     25     printf("Sequence of moves for %d disks:\n\n", n);
     26     hanoi(n, 'A', 'B', 'C');
     27 
     28     return 0;
     29 }
     30 
     31 void hanoi(int n, char from_rod, char aux_rod, char to_rod)
     32 {
     33     if (n == 1)
     34     {
     35         printf("Move disk 1 from rod %c to rod %c\n", from_rod, to_rod);
     36         return;
     37     }
     38     hanoi(n - 1, from_rod, to_rod, aux_rod);
     39     printf("Move disk %d from rod %c to rod %c\n", n, from_rod, to_rod);
     40     hanoi(n - 1, aux_rod, from_rod, to_rod);
     41 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror