Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

factorial in c++ using recursion

#include <iostream>
using namespace std;

int fact (int);
int main()
{
    cout << " Please enter your number = ";
    int n ;
    cin >> n ;

    cout << " Answer is = " << fact (n) << endl;
    return 0;
}

int fact (int n )
{
    if (n <= 1)
        return 1;
    return n * fact (n-1);
}
 
PREVIOUS NEXT
Tagged: #factorial #recursion
ADD COMMENT
Topic
Name
4+6 =