recategorized
1,773 views
4 votes
4 votes

Consider the following C language code:

#include<stdio.h>
int main() {
    int x=64;
    int i=0;
    while (i++<3)
        x=(((x<<2)+(x>>1))>>1);
    printf("%d", x);
    return 0;
}


What is the output of the above code?

recategorized

1 Answer

7 votes
7 votes
replace x as $x=\frac{(x \times 2^2)+(\frac{x}{2})}{2}$ (Only if when X is even)

When X is odd right shifting makes division but with some loss of precision.So, in case of Odd data do bitwise calculation only.

and code would work same.
edited by
Answer:

Related questions

9 votes
9 votes
3 answers
2