ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int b[] = {1, 1, 0, 1, 1, 1, 0, 1, 1, 1}, run = 0, best = 0;
for (int i = 0; i < 10; i++) {
run = b[i] ? run + 1 : 0;
if (run > best) best = run;
}
printf("%d", best);
}- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
The longest block of consecutive 1s in 1101110111 has length 3.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4, 5}; for (int i = 0; i + 1 < 5; i += 2) { int t = a[i]; a[i]…
- What is printed? c #include <stdio.h> int f(int n) { return n <= 1 ? 0 : 1 + f(n / 2); } int main(void) { printf("%d", f(10)); }
- What is printed? Assume uint16t is 16 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint16t a = 0xFFF0, b = 0x20…
- What is printed? c #include <stdio.h> long long f(int n) { return n == 0 ? 1 : 2 f(n - 1) + 1; } int main(void) { printf("%lld", f(10)); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 1000 >> 3); }
- What is printed? c #include <stdio.h> int main(void) { int c = 0; switch (3) { default: c += 1; case 1: c += 10; } printf("%d", c); }