online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** Scrivere il codice di una funzione f(n) che restituisce: - n nel caso n sia minore di 10, - il risultato di f applicata alla somma delle cifre di n se n è pari, - f(n-1) altrimenti. *******************************************************************************/ #include <iostream> using namespace std; int f(int n) { cout<<n<<endl; if(n<10){return n;} else{ int somma=0; int ntemp=n; while(ntemp!=0) { somma=somma+ntemp%10; ntemp=ntemp/10; } if(n%2==0) {return f(somma);} else {return f(n-1);} } } int main() { cout<<"inserisci un numero"<<endl; int numero; cin>>numero; cout<<"f("<<numero<<")="<<f(numero); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue