CARVIEW |
Select Language
HTTP/2 200
content-type: text/html; charset=utf-8
date: Wed, 30 Jul 2025 07:21:58 GMT
permissions-policy: interest-cohort=()
strict-transport-security: max-age=31536000; includeSubDomains
server: nginx
cache-control: s-maxage=61546, max-age=0
x-powered-by: Next.js
etag: "cqy2gea1mj9mti"
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: Miss from cloudfront
via: 1.1 8b3f40eb1b765416dfc3f89172af0efe.cloudfront.net (CloudFront)
x-amz-cf-pop: BOM78-P9
x-amz-cf-id: ZLGWZ__y_l5rPgfMv5hNm_Ysrr2kCTxx_5yXn7k0Uuo6Ip2rY-kCfA==
Algorithms | Recursion | Question 8
C++
C
Java
Python
JavaScript
Interview Preparation
- Interview Preparation For Software Developers
- Must Coding Questions - Company-wise
- Must Do Coding Questions - Topic-wise
- Company-wise Practice Problems
- Company Preparation
- Competitive Programming
- Software Design-Patterns
- Company-wise Interview Experience
- Experienced - Interview Experiences
- Internship - Interview Experiences
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