ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int od(unsigned n);
int ev(unsigned n) { return n == 0 ? 1 : od(n - 1); }
int od(unsigned n) { return n == 0 ? 0 : ev(n - 1); }
int main(void) {
printf("%d %d", ev(10), od(7));
}- A. 1 0
- B. 0 0
- C. 1 1
- D. 0 1
Correct answer: C. 1 1
ev and od call each other on n - 1, so they alternate down to zero. Ten is even, and seven is odd, so ev(10) = 1 and od(7) = 1.
More C Programming questions
- A complete binary tree of 7 nodes is stored in an array with children of node i at 2i+1 and 2i+2. The values are v = {5, 3, 8, 1, 4, 9…
- What is printed? c #include <stdio.h> #include <stdlib.h> struct Pair { int a, b; }; int cmp(const void p, const void q) { const struct…
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> int cmp(const void a, const void b) { const char x = (const…
- How many subarrays of {2, 1, 4, 3, 1, 2, 4} have a sum of exactly 7? Compute with this program. c #include <stdio.h> int main(void) { int…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 3, -1, -3, 5, 3, 6, 7}; int k = 3, dq[8], head = 0, tail = 0, total =…
- How many values x in 0..255 satisfy (x & (uint8t)-x) == x? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int…