Skip to content

Instantly share code, notes, and snippets.

@krishnanraman
Last active September 11, 2017 21:56
Show Gist options
  • Save krishnanraman/ea40cd957cc87f2b174794774f159b98 to your computer and use it in GitHub Desktop.
Save krishnanraman/ea40cd957cc87f2b174794774f159b98 to your computer and use it in GitHub Desktop.
simple c++ example
g++ * -o output
./output 4
24
#include "factorial.h"
int factorial(int x) {
if (x==1)
return 1;
else
return x * factorial(x-1);
}
int factorial(int x);
#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