2020-05-29 04:40:08 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief C++ program to find factorial of given number
|
|
|
|
*/
|
|
|
|
#include <iostream>
|
2019-12-06 06:02:52 +08:00
|
|
|
|
2020-05-29 04:40:08 +08:00
|
|
|
/** function to find factorial of given number */
|
2020-05-30 07:26:30 +08:00
|
|
|
unsigned int factorial(unsigned int n)
|
|
|
|
{
|
2019-12-06 06:02:52 +08:00
|
|
|
if (n == 0)
|
|
|
|
return 1;
|
|
|
|
return n * factorial(n - 1);
|
|
|
|
}
|
|
|
|
|
2020-05-29 04:40:08 +08:00
|
|
|
/** Main function */
|
2020-05-30 07:26:30 +08:00
|
|
|
int main()
|
|
|
|
{
|
2019-12-06 06:02:52 +08:00
|
|
|
int num = 5;
|
|
|
|
std::cout << "Factorial of " << num << " is " << factorial(num)
|
|
|
|
<< std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|