ProgrammingHardCompetitive coding (CP)

How many ways are there to tile a 1 by 4 strip with 1 by 1 and 1 by 2 tiles? The recursion computes it. What is printed?

How many ways are there to tile a 1 by 4 strip with 1 by 1 and 1 by 2 tiles? The recursion computes it. What is printed?
#include <stdio.h>
int f(int n) {
    if (n <= 1) return 1;
    return f(n - 1) + f(n - 2);
}
int main(void) {
    printf("%d", f(4));
}
  1. A. 4
  2. B. 5
  3. C. 8
  4. D. 3

Correct answer: B. 5

The tiling count follows f(n) = f(n - 1) + f(n - 2) with f(0) = f(1) = 1, so f(2) = 2, f(3) = 3 and f(4) = 5.

More C Programming questions

Exams that ask this topic