Created
January 19, 2012 00:13
-
-
Save sinannar/1636688 to your computer and use it in GitHub Desktop.
oneLineRecursiveCall return integer,if input as abcd,return is dcba
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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