McCarthy 91 function in C++

McCarthy 91 function is a recursive function used within computer science, its definition is:

McCarthy 91

Now how we implement this McCarthy 91 function in our C++ code,  have a look at the below code:

    //McCarthy 91 Function
    using namespace std;
    int M(int n)
            return(M(M(n+11))); //answer is 91 upto 101
    int main()
        int num;
        cout<<“enter a number “;
        int m = M(num);

Now in the above function M() we implemented the mathematical form of the McCarthy 91 function by using recursion because recursion is its easiest approach, we used the number taken as an argument and asked if number is greater than 100 then return number-10 else return the recursive statement as defined in the definition, and it returns the value  according to McCarthy 91 function.

Latest Content