Interesting C/C++ code

Came across this code which I think is pretty interesting 🙂

int fun(int a)
{
if(a == 1 || a == 0)
return 1;
if(a%2 == 0)
return fun(a/2) + 2;
else
return fun(a – 1) + 3;
}

void main()
{
cout << fun(5) ;
}

What would cout print? 😀

really simple and fun problem 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Protected content
Scroll to Top