Skip to content

Instantly share code, notes, and snippets.

@sms420
Created August 23, 2009 23:16
Show Gist options
  • Select an option

  • Save sms420/173539 to your computer and use it in GitHub Desktop.

Select an option

Save sms420/173539 to your computer and use it in GitHub Desktop.
recursive function examples
// recursive function examples
#include<iostream>
using namespace std;
void printForward(int p) {
if (p==0)
return;
cout << p;
printForward(p-1);
return;
}
void printBackward(int p) {
if (p==0)
return;
printBackward(p-1);
cout << p;
return;
}
int main() {
printForward(4);
cout << endl;
printBackward(4);
cout << endl;
return 0;
}
/* sample output:
$ ./a.out
4321
1234
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment