What does the following function print for n = 25?
#include <iostream>
using namespace std;
void fun(int n) {
if (n == 0)
return;
cout << n % 2;
fun(n / 2);
}
void fun(int n)
{
if (n == 0)
return;
printf("%d", n%2);
fun(n/2);
}
public class Main {
public static void fun(int n) {
if (n == 0)
return;
System.out.print(n % 2);
fun(n / 2);
}
public static void main(String[] args) {
fun(10); // Example call
}
}
def fun(n):
if n == 0:
return
print(n % 2, end='')
fun(n // 2)
function fun(n) {
if (n === 0)
return;
process.stdout.write((n % 2).toString());
fun(Math.floor(n / 2));
}
11001
10011
11111
00000
This question is part of this quiz :
Top MCQs on Recursion Algorithm with Answers