Determine the output produced by each of the following state
Solution
(a)
Given statements throws error as there is no system defined function by name \"print\".
If \"printf\" is used as an alternate to \"print\" function, six *\'s are printed in a row (for loop iterates from 0 to 5, total 6 times).
-----------------------------------------------------------------------------------------------------------------------------------------------
(b)
For loop iterates from 0 to 6 at a step count of 1.
At each iteration of i, value of i is printed in a row.
Output of executing entire for loop is: 0123456
-----------------------------------------------------------------------------------------------------------------------------------------------
(c)
Value of variable\'s n & i are initialized as n = 6, i = 7.
(i) do - while loop iterates at-least once before while condition is checked.
(ii) In the first iteration, printf statement prints value of (i*i) which is 49 (7*7).
(iii) After printing the value, while condition is checked which is 0(false) and the loop iterations stops here.
So only the value 49 is printed to console.
----------------------------------------------------------------------------------------------------------------------------------------------
(d)
Value of variable\'s n & i are initialized as n = 3, i = 5.
(i) while loop iterates at condition (i != n)
(ii) Iteration - 1:
i = 5, n = 3 => while condition is satisfied and prints value 10 ( 2 * i = 2 * 5). Output: 10
Iteration - 2:
i = 4, n = 3 => while condition is satisfied and prints value 8 ( 2 * i = 2 * 4). Output: 108 (Value 8 is placed side by 10)
Iteration - 3:
i = 3, n = 3 => while condition is failed and iteration stops here.
Output displayed on console is 108
