Solve the Problem of the Towers of Hanoi using the method recursion - C Function

C examples for Function:Recursive Function

Description

Solve the Problem of the Towers of Hanoi using the method recursion

Demo Code

#include <stdio.h>

void move(int N, char chrFrom, char chrTo, char chrTemp);

int main()//from  w  ww .j a  v a  2s. c  o m
{
    int counter = 5;

    move(counter, 'L', 'R', 'C');

    return(0);
}

void move(int N, char chrFrom, char chrTo, char chrTemp)
{
  if (N > 0) {
    move(N-1, chrFrom, chrTemp, chrTo);
    printf("Move disk %d from %c to %c\n", N, chrFrom, chrTo );
    move(N-1, chrTemp, chrTo, chrFrom);
  }
  return;
}

Related Tutorials