CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

What is the output printed by the following program?
#include < stdio.h>
int f(int n, int k)
{
if (n = = 0) return 0;
else if (n% 2) return f(n/2, 2*k)+k;
else return f(n/2, 2*k)- k;
}
int main( )
{
printf("%d", f(20, 1));
return 0;
}

A
20
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
5
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
9
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
8
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C 9

flag
Suggest Corrections
thumbs-up
3
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Fear of the Dark
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon