TheAlgorithms-C-Plus-Plus/math/factorial.cpp

21 lines
418 B
C++
Raw Normal View History

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