ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[] = {1, 2, 3, 4, 5, 6}, best = 0;
for (int i = 0; i + 3 <= 6; i++) {
int s = a[i] + a[i + 1] + a[i + 2];
if (s > best) best = s;
}
printf("%d", best);
}- A. 12
- B. 15
- C. 18
- D. 6
Correct answer: B. 15
The window sums are 6, 9, 12 and 15, so the largest is 15 from the last window.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (-17 / 5) 5 + (-17 % 5) == -17); }
- How many leading zero bits does the 16-bit value 0x0123 have? Count them with this program. c #include <stdint.h> #include <stdio.h> int…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { return atoi((const char const )a)…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { const int x = a, y = b; if (x[0] != y[0])…
- What is the digit sum of 2^15 = 32768? The recursion below computes it. Assume int is 32 bits. What is printed? c #include <stdio.h> int…
- How many subsets of {1, 2, 3} (the empty set included) have a sum divisible by 3? The recursion below counts them. What is printed? c…