Last active
September 11, 2017 21:56
-
-
Save krishnanraman/ea40cd957cc87f2b174794774f159b98 to your computer and use it in GitHub Desktop.
simple c++ example
This file contains 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
g++ * -o output | |
./output 4 | |
24 |
This file contains 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 "factorial.h" | |
int factorial(int x) { | |
if (x==1) | |
return 1; | |
else | |
return x * factorial(x-1); | |
} |
This file contains 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
int factorial(int x); |
This file contains 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 "factorial.h" | |
#include <iostream> | |
#include <cstdlib> | |
using namespace std; | |
int main(int argc, char* argv[]) { | |
int x = atoi(argv[1]); | |
cout << "Invoking factorial on " << x << endl; | |
int res = factorial(x); | |
cout << "Result: " << res << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment