0
Factorial
#include <iostream> using namespace std; int factorial(int n) { if (n==1) { return 1; } else { return n * factorial(n-1); } } int main() { cout << factorial(5); } can it be done with cin so that user has to input a numbet, and could someone give an example maybe, thanks
4 ответов
0
Sure, why not?
#include <iostream>
int factorial(int n)
{
return n <= 1 ? 1 : n * factorial(n - 1);
}
int main()
{
int n;
std::cin >> n;
std::cout << factorial(n) << std::endl;
}
+ 1
take a look at this code
https://code.sololearn.com/cTcbz3rrJaw7/?ref=app
0
Great, thanks ☺
0
I don't think you understood what I was saying