CARVIEW |
Select Language
HTTP/2 200
content-type: text/html; charset=utf-8
date: Mon, 28 Jul 2025 12:31:54 GMT
permissions-policy: interest-cohort=()
strict-transport-security: max-age=31536000; includeSubDomains
server: nginx
cache-control: s-maxage=54760, max-age=0
x-powered-by: Next.js
etag: "afntr6k5iy8ims"
content-encoding: gzip
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'self' http: https: ws: wss: data: blob: 'unsafe-eval' 'unsafe-inline'; frame-ancestors 'self';
vary: Accept-Encoding
x-cache: Hit from cloudfront
via: 1.1 0619c524a034ea5bfb96b53ac504d63a.cloudfront.net (CloudFront)
x-amz-cf-pop: BOM78-P11
x-amz-cf-id: keY5UmMA43KoUBIdZsGKqSba3cuoMUAM0h83oukAu_BxMZxTV2u3Fg==
age: 40268
Algorithms | Recursion | Question 8
C++
C
Java
Python
JavaScript
Algorithms | Recursion | Question 8
Last Updated :
Discuss
Comments
Predict the output of following program
#include <iostream>
using namespace std;
int f(int n) {
if(n <= 1)
return 1;
if(n % 2 == 0)
return f(n / 2);
return f(n / 2) + f(n / 2 + 1);
}
int main() {
cout << f(11);
return 0;
}
#include <stdio.h>
int f(int n)
{
if(n <= 1)
return 1;
if(n%2 == 0)
return f(n/2);
return f(n/2) + f(n/2+1);
}
int main()
{
printf("%d", f(11));
return 0;
}
public class Main {
public static int f(int n) {
if(n <= 1)
return 1;
if(n % 2 == 0)
return f(n / 2);
return f(n / 2) + f(n / 2 + 1);
}
public static void main(String[] args) {
System.out.println(f(11));
}
}
def f(n):
if n <= 1:
return 1
if n % 2 == 0:
return f(n // 2)
return f(n // 2) + f(n // 2 + 1)
print(f(11))
function f(n) {
if (n <= 1)
return 1;
if (n % 2 === 0)
return f(n / 2);
return f(Math.floor(n / 2)) + f(Math.floor(n / 2) + 1);
}
console.log(f(11));
Stack Overflow
3
4
5
This question is part of this quiz :
Top MCQs on Recursion Algorithm with AnswersTags:
Share your thoughts in the comments

GeeksforGeeks
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy