Created
October 30, 2017 07:46
-
-
Save techlarry/886fc34d38fe6f9c2589a139783a6f60 to your computer and use it in GitHub Desktop.
compute factorial using recursive in C++
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
// 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