C Programming · Question 14 · Hard
What will be the output of the following C program?
#include <stdio.h>
int f(int n) {
if (n == 0)
return 0;
return (n % 2) + 10 * f(n / 2);
}
int main(void) {
printf("%d", f(13));
return 0;
}
- 1011
- 13
- 1101
- 6
Answer and explanation
Answer: C. 1101
Explanation: Each call keeps n % 2 as the last digit and shifts the result of f(n / 2) one decimal place left, so the function writes n in binary using decimal digits. 13 in binary is 1101.
Previous: What will be the output of the following C program? · Next: What will be the output of the following C program?
Practise c programming
Try a fresh set of c programming questions with an explanation after every answer, free and without signing up: C Programming practice. Or sit a full placement mock test.
More c programming questions
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
More technical & programming practice
Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge