GeeksforGeeks » C/C++ Programming Questions

Explain functionality of the given recursive C function

(2 posts)
  1. ganesh
    guest
    Posted 1 year ago #

    int func(int i)
    {
      if(i%2) return (i++);
      else return func(func(i-1));
    }
    
  2. Shekhu
    Member
    Posted 1 year ago #

    If n is odd then returns n, else returns (n-1). Eg., for n = 12 you get 11 and for n = 11 you get 11. In this statement "return i++" returns value of i only as it is a post increment.


Reply

You must log in to post.

RSS feed for this topic