Skip to content

Instantly share code, notes, and snippets.

@techlarry
Created October 30, 2017 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techlarry/886fc34d38fe6f9c2589a139783a6f60 to your computer and use it in GitHub Desktop.
Save techlarry/886fc34d38fe6f9c2589a139783a6f60 to your computer and use it in GitHub Desktop.
compute factorial using recursive in C++
// A simple recursive function has two main parts: the base-case part, where it computes a vaue and terminates,
// and the recursive part, where it calls itself.
#include <iostream>
//Recursive factorial function
//
//#include<iostream>
using namespace std;
//Recursive factorial function
//
long factorial (int n)
{
if (n<=1)
return 1;
else
return n*factorial(n-1);
}
int main()
{
int i = 3;
cout << "\n Factorial of 3 is " << factorial(i) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment