Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
Question 5
|
Consider the following C function.
void convert (int n) { if (n < 0) printf ("%d", n); else { convert (n/2); printf ("%d", n%2); } }
Which one of the following will happen when the function convert is called with any positive integer n as argument?
It will print the binary representation of n in the reverse order and terminate.
|
|
It will not print anything and will not terminate.
|
|
It will print the binary representation of n and terminate.
|
|
It will print the binary representation of n but will not terminate.
|
Question 5 Explanation:
////////////////OUTPUT
Sequence of function calls
Convert(6)
Convert(3)
Convert(1)
Sequence of function calls
Convert(6)
Convert(3)
Convert(1)
Convert(0)
:
Convert(0)
:
:
It will not terminate and never produce any output.
Note:
There is no instruction which stops the loop.
Correct Answer: B
Question 5 Explanation:
////////////////OUTPUT
Sequence of function calls
Convert(6)
Convert(3)
Convert(1)
Sequence of function calls
Convert(6)
Convert(3)
Convert(1)
Convert(0)
:
Convert(0)
:
:
It will not terminate and never produce any output.
Note:
There is no instruction which stops the loop.
Subscribe
Login
0 Comments