ProgrammingHardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int a[] = {1, 2, 2, 3, 1, 4};
    int c = 0;
    for (int i = 0; i < 5; i++)
        if (a[i] < a[i + 1]) c++;
    printf("%d", c);
}
  1. A. 2
  2. B. 3
  3. C. 4
  4. D. 5

Correct answer: B. 3

The adjacent pairs are (1,2), (2,2), (2,3), (3,1) and (1,4), and the strictly increasing ones are (1,2), (2,3) and (1,4). Counting non-strict increases would give 4.

More C Programming questions

Exams that ask this topic