Skip to content

Instantly share code, notes, and snippets.

@sinannar
Created January 19, 2012 00:13
Show Gist options
  • Save sinannar/1636688 to your computer and use it in GitHub Desktop.
Save sinannar/1636688 to your computer and use it in GitHub Desktop.
oneLineRecursiveCall return integer,if input as abcd,return is dcba
#include<iostream>
using namespace std;
/*
int number(int a,int b=0){ return(a==0 ? b : number(a/10,b*10+a%10));}
understandable form of this recursive call
*/
int number(int i,int a,int b=0)
{
cout<<"i="<<i<<" a="<<a<<" b="<<b<<endl;
++i;
if(a==0)
return b;
else
return number(i,a/10,b*10+a%10);
}
int main(void)
{
cout<<number(0,1234);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment