Question 4 - Calculate (a! + b!)

 avatar
itsLu
c_cpp
a year ago
428 B
18
Indexable
// 4. Write a program to calculate a! + b! without using any loop.
#include <iostream>
using namespace std;

int rec_factorial (int n)
{
    if (n == 0 || n == 1)
        return 1;
    else
        return n * rec_factorial(n-1);
}

int main()
{
    int a, b, res;
    cout << "Please enter a, b: " << endl;
    cin >> a >> b;
    res = rec_factorial(a) + rec_factorial (b);
    cout << "Result = " << res;
}
Leave a Comment