ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int m[2][2] = {{3, 1}, {4, 2}};
int s = 0;
for (int i = 0; i < 2; i++) {
int lo = m[i][0] < m[i][1] ? m[i][0] : m[i][1];
s += lo;
}
printf("%d", s);
}- A. 4
- B. 6
- C. 5
- D. 3
Correct answer: D. 3
The ternary picks the smaller entry of each row: min(3, 1) = 1 and min(4, 2) = 2, total 3. 4 takes the column minima (3 + 1) instead of the row minima.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int r0[2] = {1, 2}, r1[2] = {3, 4}; int rows[2] = {r0, r1}; int t = rows[0]…
- What is printed? The reverse of the binary digits of 13 (1101) is taken as an integer. c #include <stdio.h> int main(void) { unsigned x =…
- How many occurrences of the two-letter string "ab" are in "abcabab"? Count them with this program. c #include <stdio.h> int main(void) {…
- What is printed? c #include <stdio.h> int main(void) { int c = 0; switch ('b') { case 'a': c++; case 'b': c += 10; case 'c': c += 100…
- How many nodes are at depth 2 in a perfect binary tree of depth 3 (the root is depth 0)? The program counts them recursively. c #include…
- What is printed? Each struct has an int a and an int b. c #include <stdio.h> #include <stdlib.h> struct P { int a, b; }; int cmp(const…