ProgrammingHardGATE CS · Competitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int der(int n) {
if (n == 0) return 1;
if (n == 1) return 0;
return (n - 1) * (der(n - 1) + der(n - 2));
}
int main(void) {
printf("%d", der(4));
}- A. 8
- B. 9
- C. 6
- D. 24
Correct answer: B. 9
der(n) counts permutations with no fixed point, and der(4) = 3 * (der(3) + der(2)) = 3 * (2 + 1) = 9. The value 24 is 4!, which counts all permutations.
More C Programming questions
- How many subsets of {1, 2, 3, 4, 5} sum to 6? Compute with this recursive program. c #include <stdio.h> int v[5] = {1, 2, 3, 4, 5}; int…
- What is printed? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint8t x = 0x1C; int c = 0; for (int i…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 3, r = 0; for (int i = 0; i < 4; i++) { r = (r << 1) | (x & 1u); x >>=…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0xABCD, p = 0; while (x) { p ^= x & 1u; x >>= 1; } / p is the parity…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint32t a = 0xFFFFFFF0u, b = 0x20u; uint32t s = a + b; int…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { int16t a = 200, b = 200; int p = a b; printf("%d %d", p, p >…