GATE Computer ScienceEasyGATE CS (PYQ pattern)
int a[3][4] = {{3,1,4,1},{5,9,2,6},{5,3,5,8}}; int t = 0; for (int j = 0; j < 4; j++) for (int i = 0; i < 3; i++) t += *(*(a + i) + j) * (j + 1) * (i % 2 + 1); What is t?
- A. 175
- B. 185
- C. 197
- D. 52
Correct answer: B. 185
Weight each element by (column + 1) and by 2 for the middle row (1 for rows 0 and 2): the sum is 185.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A queue is a circular array that starts with capacity 4 and doubles (copying every element) when an enqueue finds it full; dequeues never…
- unsigned char x = 0x5B; unsigned s = 0; for (int i = 0; i < 6; i++) { x ^= (unsigned char)(x << 3); x ^= x >> 2; s += x; } printf("%u %u"…
- A bracket checker pushes every opening bracket and, on a closing bracket, pops and compares. For the string {[()()]([{}])}[({[]}) the…
- A queue holds 5, 12, 7, 3, 9, 14, 2, 8 (front first). To reverse the first 5 elements, they are dequeued onto a stack, popped back and…
- In the binary tree (key, left, right) = (44, (20, (12), (8)), (24, (9, (4), (5)), (15, -, (15)))), how many non-leaf nodes have a key…
- int ds(int n) { return n < 10 ? n : ds(n / 10) + n % 10; } int steps(int n) { int c = 0; while (n >= 10) { n = ds(n); c++; } return c; }…