recategorized by
3,200 views
24 votes
24 votes

The following recursive function in C is a solution to the Towers of Hanoi problem.

void move(int n, char A, char B, char C)  {
    if (......................) {
        move (.............................);
        printf("Move disk %d from pole %c to pole %c\n", n, A, C);
        move (.....................);
    }
}

Fill in the dotted parts of the solution.

recategorized by

2 Answers

Best answer
29 votes
29 votes
void move(int n, char A, char B, char C) {
    if (n > 0) {
        move (n-1, A, C, B);
        printf("Move disk %d from pole %c to pole %c\n", n, A, C);
        move (n-1, B, A, C);
    } 
}
edited by
7 votes
7 votes
If(n==1) { Printf("\n %s %c %s %c","move disk1 from pole",A,"to pole",B); Return; } Towers(n-1,A,C,B); Printf.... Towers(n-1,C,B,A);

Related questions

35 votes
35 votes
3 answers
2
Kathleen asked Sep 15, 2014
10,081 views
The C language is:A context free languageA context sensitive languageA regular languageParsable fully only by a Turing machine
39 votes
39 votes
4 answers
3
Kathleen asked Sep 15, 2014
27,673 views
Consider the following declaration of a two-dimensional array in C:char $a[100][100]$;Assuming that the main memory is byte-addressable and that the array is stored start...
13 votes
13 votes
2 answers
4
Kathleen asked Sep 15, 2014
8,184 views
The results returned by function under value-result and reference parameter passing conventionsDo not differDiffer in the presence of loopsDiffer in all casesMay differ i...