GATE Computer ScienceHardGATE CS (PYQ pattern)
char s[] = "GATECS"; for (int i = 1; s[i]; i++) s[i] = 'A' + (s[i] + s[i - 1] - 2 * 'A') % 26; printf("%s", s); What is printed?
- A. GGTXGU
- B. GGZDFY
- C. GGZDFX
- D. GAZDFX
Correct answer: C. GGZDFX
Letters are 0-based (A = 0). s[i - 1] is read after it has already been updated: G stays 6; A: 0 + 6 = 6 -> G; T: 19 + 6 = 25 -> Z; E: 4 + 25 = 29 mod 26 = 3 -> D; C: 2 + 3 = 5 -> F; S: 18 + 5 = 23 -> X. Using the original neighbours instead gives GGTXGU.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- unsigned int i, s = 0; for (i = 5; i-- > 0; ) s += i; printf("%u %u", s, i); What is printed?
- int a = 7, b = 2; float f = a / b + a / 2.0 + (float)(a / b) b; printf("%.2f %d", f, (int)(a / b 2.0)); What is printed?
- int a = 5, b = 3, c = 2; int x = a + b << c > 20; int y = 6 & 3 == 3; int z = 1 + 2 3 % 4 - 5 / 2 | 8 >> 2; printf("%d %d %d", x, y, z)…
- int C(int n, int k) { if (k == 0 || k == n) return 1; if (k == 1) return n; return C(n - 1, k - 1) + C(n - 1, k); } How many calls to C…
- Elements 1, 2, 3, 4, 5, 6 are pushed in this order onto a stack, with pops allowed at any time until all are popped. Of all possible…
- An input-restricted double-ended queue lets items 1, 2, 3, 4, 5 be inserted only at the rear (in that order) while removals are allowed at…