Tuesday, November 14, 2017

C++ program to Calculate Factorial Using Recursion

    This program takes a positive integer from user and calculates the factorial of that number. Suppose, user enters 6 then,
Factorial will be equal to 1*2*3*4*5*6 = 720
You'll learn to find the factorial of a number using a recursive function in this example.
If you face any problem with the code please put your question into the comment box below....

    #include <bits/stdc++.h>

    using namespace std;

    int factorial(int n) {
        if(n > 1)
            return n * factorial(n-1);
        else
            return 1;
    }
    int main() {
        int n;
        cin >> n;
        int result = factorial(n);
        cout << result << endl;
        return 0;
    }

No comments:

Post a Comment

কম্পিউটার প্রোগ্রামিং শেখা কতটা গুরুত্বপূর্ণ ?

প্রোগ্রামিং কতটা গুরুত্বপূর্ণ? কম্পিউটার বিজ্ঞানের অনেক বড় একটা অংশ জুড়েই রয়েছে প্রোগ্রামিংয়ের দখল। প্রোগ্রামিং ছাড়া আমর...