day 2 commit & changed day 1 filenames
This commit is contained in:
parent
d5f4f817c0
commit
703fcae148
6 changed files with 99 additions and 0 deletions
19
D2_factorial.cpp
Normal file
19
D2_factorial.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <iostream>
|
||||
|
||||
int factorial(int n) {
|
||||
if (n <= 0) {
|
||||
return -1;
|
||||
} else if (n > 1) {
|
||||
return n * factorial(n - 1); //n * n-1 * n-2....
|
||||
} else return 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
|
||||
std::cout << "Enter n to do n!: ";
|
||||
std::cin >> n;
|
||||
|
||||
std::cout << "Ans: " << factorial(n) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue