Write recursive function int Fac (int n) to find the factorial of n, then the main function calls the recursive function to calculate S = M! + N! ( M <= 10, N <= 10) values.
The so-called factorial means 2 multiplied by 3 1 from 4 multiplied by up to a desired number. Factorial symbol "!" To indicate, for example, 5 factorial is 5! = 1 * 2 * 3 * 4 * 5.
#include <iostream>
#include "SumOfFactorial.h"
using namespace std;
int Fac(int n)
{
if(n==0||n==1)
{
return 1;
}
else
{
return n*Fac(n-1);
}
}
int main()
{
int M, N, sum = 0;
cin >> M >> N;
sum = Fac(M) + Fac(N);
cout << M << "!+" << N << "!=" << sum << endl;
}