# GATE | GATE-CS-2003 | Question 88

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
(A) {m | m ≤ n, (∃ i) [m = i!]} Here i! mean factorial of i
(B) {m | m ≤ n, (∃ i) [m = i2]}
(C) {m | m ≤ n, m is prime}
(D) {}

Explanation:

 `// 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); `

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.