Question 12964 – Operating-Systems
January 11, 2024कंप्यूटर-नेटवर्क
January 11, 2024Programming-for-Output-Problems
Question 30 |
Consider the following C program
How many lines of output does this program produce?
0-9 lines of output | |
10-19 lines of output | |
20-29 lines of output | |
More than 29 lines of output |
Question 30 Explanation:
→ Since there is one line of output for each loop, we need to determine the number of
times the loop executes. Since i is constant, we need to see the growth of j only.
→ Let the initial value of j be denoted by J1 and the subsequent values by Jn for n= 2, 3,… so that J denotes a progression of j. We see that Jn = 2Jn-1;
→ J1 = 2, which gives Jn = 2n-1;
n = 1, 2, …
→ The loop will execute as long as i/j=2.0/2n-1 >0.001 which gives n<3log210+2 (or) n<11.97.
→ Thus the loop will execute 11 times which is equivalent to say there will be 11 lines of output.
times the loop executes. Since i is constant, we need to see the growth of j only.
→ Let the initial value of j be denoted by J1 and the subsequent values by Jn for n= 2, 3,… so that J denotes a progression of j. We see that Jn = 2Jn-1;
→ J1 = 2, which gives Jn = 2n-1;
n = 1, 2, …
→ The loop will execute as long as i/j=2.0/2n-1 >0.001 which gives n<3log210+2 (or) n<11.97.
→ Thus the loop will execute 11 times which is equivalent to say there will be 11 lines of output.
Correct Answer: D
Question 30 Explanation:
→ Since there is one line of output for each loop, we need to determine the number of
times the loop executes. Since i is constant, we need to see the growth of j only.
→ Let the initial value of j be denoted by J1 and the subsequent values by Jn for n= 2, 3,… so that J denotes a progression of j. We see that Jn = 2Jn-1;
→ J1 = 2, which gives Jn = 2n-1;
n = 1, 2, …
→ The loop will execute as long as i/j=2.0/2n-1 >0.001 which gives n<3log210+2 (or) n<11.97.
→ Thus the loop will execute 11 times which is equivalent to say there will be 11 lines of output.
times the loop executes. Since i is constant, we need to see the growth of j only.
→ Let the initial value of j be denoted by J1 and the subsequent values by Jn for n= 2, 3,… so that J denotes a progression of j. We see that Jn = 2Jn-1;
→ J1 = 2, which gives Jn = 2n-1;
n = 1, 2, …
→ The loop will execute as long as i/j=2.0/2n-1 >0.001 which gives n<3log210+2 (or) n<11.97.
→ Thus the loop will execute 11 times which is equivalent to say there will be 11 lines of output.