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

Consider the following C code. Assume that unsigned long int type length is 64 bits.
unsigned long int fun (unsigned long int n) {
unsigned long int i, j = 0, sum = 0;
for (i = n; i > 1; i = i/2) j ++;
for (;j > 1; j = j/2) sum++;
return (sum);
}
The value returned when we call fun with the input 240 is

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

The correct option is D 5
First for loop deal with value of 'j':
1. for (i = n; i > 1, i = i/2)
j++;
When 2=240 will make
j=log(240)= 40.
Second for loop deal with value of 'sum':
Now for j = 1 loop will terminate and return sum = 5.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Integration by Substitution
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon