C Source Code

/* Author: Hannes du Plooy */
/* Date: 20 Sep 2016       */
/* Objective: To solve the towers of hanoi with number of discs provided in the arguments to calling the program */

#include <stdio.h>
#include <stdlib.h>

void hanoi(int source, int dest, int other, int discs) {
    if (discs == 0) 
        return;
    hanoi(source,other,dest,discs-1);
    printf("Move from %d to %d\n",source,dest);
    hanoi(other,dest,source,discs-1);
}

int main(int argc, char **argv) {
    if (argc < 2) {
        return -1;
    }
    int discs = atoi(argv[1]);
    hanoi(0,2,1,discs);
}