mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
bc8e8dfc2b
* Create factorial.cpp * Update and rename Math/factorial.cpp to math/factorial.cpp * Update factorial.cpp * Update factorial.cpp
18 lines
383 B
C++
18 lines
383 B
C++
// C++ program to find factorial of given number
|
|
#include<iostream>
|
|
|
|
// function to find factorial of given number
|
|
unsigned int factorial(unsigned int n) {
|
|
if (n == 0)
|
|
return 1;
|
|
return n * factorial(n - 1);
|
|
}
|
|
|
|
// Driver code
|
|
int main() {
|
|
int num = 5;
|
|
std::cout << "Factorial of " << num << " is " << factorial(num)
|
|
<< std::endl;
|
|
return 0;
|
|
}
|