Q.Consider the following program segment in C programming language : i = 6720; j = 4; while ((i % j) == 0) {i = i / j; j = j + 1;} On termination, j will have the value
Correct answer: 9
Explanation
Analyze the given C program segment. • Initially, i = 6720 and j = 4 • The while loop will continue as long as (i%j) = = 0, meaning i is divisible by j. First iteration (j = 4): • i % 4 = = 6720 % 4 = = 0 (true), so the loop executes. • Now, i = i/j = 6720/4 = 1680 • j = j + 1 = 4 + 1 = 5 Sixth iteration (j = 9): • i % 9 = = 1 % 9 = = 0 (false) So the loop terminates. Hence, the loop terminates when j = 9, so the value of j at termination is 9.
Analyze the given C program segment. • Initially, i = 6720 and j = 4 • The while loop will continue as long as (i%j) = = 0, meaning i is divisible by j. First iteration (j = 4): • i % 4 = = 6720 % 4 = = 0 (true), so the loop executes. • Now, i = i/j = 6720/4 = 1680 • j = j + 1 = 4 + 1 = 5 Sixth iteration (j = 9): • i % 9 = = 1 % 9 = = 0 (false) So the loop terminates. Hence, the loop terminates when j = 9, so the value of j at termination is 9.