edited by
12,278 views
56 votes
56 votes

In the following $C$ program fragment, $j$, $k$, $n$ and TwoLog_n are integer variables, and $A$ is an array of integers. The variable $n$ is initialized to an integer $\geqslant 3$, and TwoLog_n is initialized to the value of $2^*\lceil \log_2(n) \rceil$

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

  1. $\left\{m \mid m \leq n, (\exists i)\left[m=i!\right]\right\}$

  2. $\left\{m \mid m \leq n, (\exists i) \left[m=i^2\right]\right\}$

  3. $\left\{m \mid m \leq n, \text{m is prime} \right\}$

  4. { }

edited by

7 Answers

4 votes
4 votes

The answer is D;

suppose n=4 and TwoLog_n=4;

after executing the code, in place of  { if (!A[j]) printf("%d", j);} if we write { if (A[j]) printf("%d", j);}

then it will print 34 because A[3]=1,a[4]=1; but we are checking for {(!A[j]} from index 3 to 4 so it will print nothing.

0 votes
0 votes
as per Geeksofgeeks why answer show me B.

explanation:

[sourcecode language="C"] // Initialize all values as 0 for (k = 3; k < = n; k++) A[k] = 0; for (k = 2; k < = TwoLog_n; k++) for (j = k + 1; j < = n; j++) // If k divides j, then A[j] is // set as 0, else non-zero A[j] = A[j] || (j % k); // Print all numbers where A[j] is 0 for (j = 3; j < = n; j++) if (!A[j]) printf("%d", j); [/sourcecode]
0 votes
0 votes

In simple words, it is trying to find ’ i‘ such that i%((i-1)!)=0 for i>=3  it is impossible.

So, it will return an empty set.

Answer:

Related questions

27 votes
27 votes
3 answers
1
Kathleen asked Sep 16, 2014
10,217 views
Consider the following $C$ function.For large values of $y$, the return value of the function $f$ best approximatesfloat f,(float x, int y) { float p, s; int i; for (s=1,...
50 votes
50 votes
11 answers
4
Kathleen asked Sep 17, 2014
14,315 views
The following are the starting and ending times of activities $A, B, C, D, E, F, G$ and $H$ respectively in chronological order: $“a_s \: b_s \: c_s \: a_e \: d_s \: c_...