Below is C code and Python code for an algorithm.
C code:
void foo( int n,...
Below is C code and Python code for an algorithm.
C code:
void foo( int n, int A, int B, int C ) {
if( n==1 ) {
printf("%d to %d\n",A,B);
return;
}
foo( n-1, A, C, B );
printf("%d to %d\n",A,B);
foo( n-1, B, C, A );
Python code:
def foo(n , A, B, C):
if n==1:
print A, "to", B
return
foo(n-1, A, C, B)
print A, "to", B
foo(n-1, B, C, A)
Let Hn be the number...
The code segment in Listing 1, when completed and executed,
creates nums, an uninitialized 4-integer array....
The code segment in Listing 1, when completed and executed,
creates nums, an uninitialized 4-integer array. It stores
4 and 5 as the first and second elements, respectively, of the
array. It adds the first and second elements of the array and
stores their sum as the third element of the nums. It
prints the third element of nums. It then adds the second
and third elements of the array and stores their sum as the fourth
element of nums....