Saturday 18 November 2017

C++ Program to Find Factorial of a Number using Recursion


Code:

#include   cstring
#include   iostream
#include   cstdlib
#define ll long long
using namespace std;
/* 
 * Find Factorial of a Number using Recursion
 */
ll fact_recur(int n)
{
    if (n == 0 || n == 1)
        return 1;
    else
        return n * fact_recur(n - 1);
}
/* 
 * Main
 */
int main()
{
    int n;
    while (1)
    {
        cout<<"Enter interger to compute factorial(0 to exit): ";
        cin>>n;
        if (n == 0)
            break;
        cout<
    }
    return 0;
}


Output:

Enter interger to compute factorial(0 to exit): 10
3628800
Enter interger to compute factorial(0 to exit): 20
2432902008176640000
Enter interger to compute factorial(0 to exit): 15
1307674368000
Enter interger to compute factorial(0 to exit): 0

------------------
(program exited with code: 1)
Press return to continue


More C++ Programs:













100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...