mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-11 06:26:05 +08:00
factorial.cpp (#561)
* Create factorial.cpp * Update and rename Math/factorial.cpp to math/factorial.cpp * Update factorial.cpp * Update factorial.cpp
This commit is contained in:
committed by
Christian Clauss
parent
b53bdf16ec
commit
bc8e8dfc2b
17
math/factorial.cpp
Normal file
17
math/factorial.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user