Given the piece of C code void main int m 2 int n 4 forin

Given the piece of C code void main() { int m = 2; int n = 4; for(int i = 1; i = m; i = i + 1) { for(int j = 1: j 2) { printf(\" [%d,%d]\ \", i, j); } } } } a)Write the 3rd line of the output:

Solution

Ans : [2,3].

Explanation :

- there are two for loops, first for loop will execute for two repetitions and second one will execute 4 repetitions(there will be total of 8 repetition for second loop)

-During first execution of first for loop, the second for loop prints values when value of \" j \" reaches 3 (i.e. this loop will print values of \" i \"and \" j \" only 2 times out of 4 repetitions).

-During second execution of first for loop, the second for loop will print another 2 values.

-Hence output will have total 4 values of \" i \" and \" j \" (2 values during first execution and another 2 values in second execution of first for loop).

Output :

[1,3]

[1,4]

[2,3]

[2,4]

*feedback is appreciated if the answer is satisfying.

 Given the piece of C code void main() { int m = 2; int n = 4; for(int i = 1; i = m; i = i + 1) { for(int j = 1: j 2) { printf(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site