Type a number \$n\$. Then calculate \$f(n)\$, where
$$ f(n) = \begin{cases} n-10 & \text{if}~ n > 100\\[1.5ex] f(f(n + 11)) & \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 <iostream>
using namespace std;
int main(){
int i=0, n, x, k;
cin>>n;
if(n>100) {
cout<<"f("<<n<<")=";
n=n-10;
}
else {
cout<<"f("<<n<<")=";
while(n<=100){
loop:
x=0;
k=0;
i++;
n+=11;
while(x<=i){
x++;
cout<<"f(";
}
cout<<n;
while(k<=i){
k++;
cout<<")";
}
cout<<"=";
if(n>100){
x=0;
k=0;
i=i-1;
n=n-10;
while(x<=i){
x++;
cout<<"f(";
}
cout<<n;
while(k<=i){
k++;
cout<<")";
}cout<<"=";
}
if(n>100){
x=0;
k=0;
i=i-1;
n=n-10;
if(i>=0){
while(x<=i){
x++;
cout<<"f(";
}
cout<<n;
while(k<=i){
k++;
cout<<")";
}cout<<"=";
goto loop;
}
break;
}
}
}cout<<n;
}