Recurrence, recursive function Type a number \$n\$. Then calculate \$f(n)\$, where

$$ f(n) =
\begin{cases}
n-10 &amp; \text{if}~ n &gt; 100\\[1.5ex]
f(f(n + 11)) &amp; \text{otherwise}
\end{cases}
$$

The output must show all the computations, such as 
$$f(99) = f(f(110)) = f(100) = f(f(111)) = f(101) = 91$$

Is there a shorter and better way I can solve this?

#include &lt;iostream&gt;
using namespace std;

int main(){
    int i=0, n, x, k;

cin&gt;&gt;n;

if(n&gt;100) {
cout&lt;&lt;"f("&lt;&lt;n&lt;&lt;")=";
n=n-10;
}
else {
    cout&lt;&lt;"f("&lt;&lt;n&lt;&lt;")=";
while(n&lt;=100){
loop:       
x=0;
k=0;
i++;
n+=11;
        while(x&lt;=i){                         
            x++;
            cout&lt;&lt;"f(";
        }
        cout&lt;&lt;n;
        while(k&lt;=i){
            k++;
            cout&lt;&lt;")";  
        }
        cout&lt;&lt;"=";  
    if(n&gt;100){

        x=0;
        k=0;
        i=i-1;
        n=n-10;



        while(x&lt;=i){                         
            x++;
            cout&lt;&lt;"f(";
        }
        cout&lt;&lt;n;
        while(k&lt;=i){
            k++;
            cout&lt;&lt;")";

        }cout&lt;&lt;"=";
    }


        if(n&gt;100){

        x=0;
        k=0;
        i=i-1;
        n=n-10;

        if(i&gt;=0){

        while(x&lt;=i){                         
            x++;
            cout&lt;&lt;"f(";
        }
        cout&lt;&lt;n;
        while(k&lt;=i){
            k++;
            cout&lt;&lt;")";

        }cout&lt;&lt;"=";

        goto loop;
    }
         break;
    } 
    }
    }cout&lt;&lt;n;
 }
There's no way to tell this in a friendly manner: your indentation is abysmal.

Let's fix that up first. Note that there's plenty left to improve, like giving your operators some space, but I'll leave that as an exercise for yourself. Keep in mind space is cheap and readability is very important in code. If you can add readability by using some extra newlines or space, do it. But only if it helps. Don't throw them needlessly around just for the sake of it.

#include &lt;iostream&gt;
using namespace std;

int main(){
    int i=0, n, x, k;
    cin&gt;&gt;n;
    if(n&gt;100) {
        cout&lt;&lt;"f("&lt;&lt;n&lt;&lt;")=";
        n=n-10;
    }
    else {
        cout&lt;&lt;"f("&lt;&lt;n&lt;&lt;")=";
        while(n&lt;=100){
            loop:       
                x=0;
                k=0;
                i++;
                n+=11;
                while(x&lt;=i){                         
                    x++;
                    cout&lt;&lt;"f(";
                }
                cout&lt;&lt;n;
                while(k&lt;=i){
                    k++;
                    cout&lt;&lt;")";  
                }
                cout&lt;&lt;"=";  
                if(n&gt;100){
                    x=0;
                    k=0;
                    i=i-1;
                    n=n-10;
                    while(x&lt;=i){                         
                        x++;
                        cout&lt;&lt;"f(";
                    }
                    cout&lt;&lt;n;
                    while(k&lt;=i){
                        k++;
                        cout&lt;&lt;")";
                }
                cout&lt;&lt;"=";
            }
            if(n&gt;100){
                x=0;
                k=0;
                i=i-1;
                n=n-10;
                if(i&gt;=0){
                    while(x&lt;=i){                         
                        x++;
                        cout&lt;&lt;"f(";
                    }
                    cout&lt;&lt;n;
                    while(k&lt;=i){
                        k++;
                        cout&lt;&lt;")";
                    }
                    cout&lt;&lt;"=";
                    goto loop;
                }
                break;
            } 
        }
    }
    cout&lt;&lt;n;
 }


Much better, but plenty left to improve.

Namespaces

using namespace std; is considered bad practice. Short code is not a requirement in C++, clear code is preferred. It's a thing commonly taught to new C++ programmers because it's 'easier', but it will royally bite you in the behind when conflicts arise.

goto

I'm not going to re-iterate how evil goto is, but please take a look at this well-written answer by 200_success. Basically, one should only use it in C++ if you know exactly what you're doing and there's no better alternative. There usually is a better alternative!

Be consistent!

x++ is usually reserved for for loops. Doing it in while loops indicates you're using the wrong tool for the job. You use x++, x += 1 and x = x + 1 or the negative version of it all over the place. There usually is no reason to write i = i -1, i -= 1 will do.

But the worst of it is:

Your code is simply incomprehensible. It takes too long to understand what it does and all the re-declaring of variables makes it hard to track what's going on. One-letter variables are usually not a good idea, iterators in for loops are an acceptable exception.

You have 6 while loops in your main function. 6!. I'd expect at least 3 different functions to keep this readable, with sensible returns passing the data along and there can't be a good reason to have this many while loops.

So?

Write down what you want to do as a flow-chart. Simplify it as much as possible. Implement that. The result will be half as complicated and twice as readable, at least. What you currently have is the result of a design flaw. I'm afraid a re-design, with this answer in the back of your head, is the only sensible solution here.