Monday, January 18, 2021
Home C / C++ McCarthy 91 function in C++

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.

- Advertisment -

Most Popular

Android Webview Tutorial With Example | How to Use Webview in Android

Android Webview Tutorial With Example Have you seen an Android app displaying Web content using Webview. This Android Webview Tutorial is about integrating Webview using Android Studio....

Student Registration Project in PHP

In this Student Registration Project we are providing a form in simple html to the student and that form sends the data to "student.php"...

Java GUI Calculator Source Code

Here we have a Java GUI Calculator Source Code for you in which a Java GUI calculator has been created using "swing" and "awt". The calculator has...

Numeric Array in PHP

Numeric arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero....