CPP Program to find the factorial by recursion

 In this program, the solution of finding the factorial of any number positive number by using the recursion method in the cpp language. For a complete understanding of this code, you must have knowledge of the cpp recursion.



using namespace std;

int fact(int n); //declare the function

int main()


    int n;

    cout << "Enter a positive integer for finding the factorial ";

    cin >> n;

    cout << "Factorial of the number " << n << "= " << fact(n);

    return 0;


int fact(int n) //define the function for factorial


    if(n >= 1)

        return n * fact(n - 1);


        return 1;


Enter a positive integer for finding the factorial 4
Factorial of the number 4= 24


Hire a programmer

Popular posts from this blog

CSS selector

C program to convert decimal to binary number

C Program to convert binary to decimal number