Question 7146 – NVS PGT CS 2019 Part-A
November 23, 2023
Question 1261 – Algorithms
November 23, 2023
Question 7146 – NVS PGT CS 2019 Part-A
November 23, 2023
Question 1261 – Algorithms
November 23, 2023

Question 9666 – C-Programming

In the following C program fragment, j, k n and TwoLog_n are interger variables, and A is an array of integers. The variable n is initialized to an integer ≥3, and TwoLog_n is initialized to the value of 2*⌈log2(n)⌉

   for (k = 3; k < = n; k++)
               A[k] = 0;
   for (k = 2; k < = TwoLog_n; k++)
          for (j = k + 1; j < = n; j++)
                    A[j] = A[j] || (j%k);
   for (j = 3; j < = n; j++)
          if (!A[j]) printf("%d", j); 

The set of numbers printed by this program fragment is

Correct Answer: D

Question 5 Explanation: 
Take n=4, so Two log_n=4
Now Trace the code,
for (k=3; k<=n; k++)
A[k]=0; // A[3]=0
A[4]=0
for (k=2; k<=Two log_n; k++)
for(j=k+1; j<=n; j++)
A[j] = A[j] // (j%k); // A[3] = 0 // I=1
A[4] = 0 // I=1
for (j=3; j<=n; j++)
if (!A[j]) printf(“%d”, j);
// if (!1) means if (0), so printf will never execute
Hence, Option (D) is the answer.
A
{m|m ≤ n, (∃i)[m=i!]}
B
{m|m ≤ n, (∃i)[m=i2]}
C
{m|m ≤ n, m is prime}
D
{ }
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!