ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
int main(void) {
    int n = 4;
    int triangle = n * (n + 1) / 2;
    printf("%d", triangle);
}
  1. A. 16
  2. B. 6
  3. C. 10
  4. D. 8

Correct answer: C. 10

This computes the nth triangular number: 4*5/2 = 20/2 = 10 (equivalently 1+2+3+4=10).

More C Programming questions

Exams that ask this topic