ProgrammingHardTCS NQT · Infosys
How many times does the value change between neighbours in {1, 1, 2, 2, 2, 3, 1}? Compute with this program.
How many times does the value change between neighbours in {1, 1, 2, 2, 2, 3, 1}? Compute with this program.
#include <stdio.h>
int main(void) {
int a[] = {1, 1, 2, 2, 2, 3, 1}, c = 0;
for (int i = 0; i + 1 < 7; i++)
if (a[i] != a[i + 1]) c++;
printf("%d", c);
}- A. 2
- B. 4
- C. 6
- D. 3
Correct answer: D. 3
The changes are 1 to 2, 2 to 3 and 3 to 1, so the count is 3.
More C Programming questions
- How many numbers from 1 to 100 are divisible by 4 but not by 3? Compute with this program. c #include <stdio.h> int main(void) { int c =…
- What is printed by this memoised recursion? The static memo table starts with every entry zero, and calls counts each call to f. c…
- What is printed? c #include <stdio.h> int main(void) { int arr[2 3 + 1]; printf("%zu", sizeof arr / sizeof arr[0]); }
- How many paths go from the top-left to the bottom-right of a 3 by 3 grid of points, moving right or down, without passing through the…
- What is printed? c #include <stdio.h> int main(void) { int a = 2147483647; printf("%u", (unsigned)a + 1u); }
- How many integers from 1 to 64 have their low three bits all clear? Compute with this program. c #include <stdio.h> int main(void) { int c…