{
22 29uint64_t
factorial(uint8_t n) {
30 if(n > 20) {
31 throwstd::invalid_argument(
"maximum value is 20\n");
32}
33 if(n == 0) {
34 return1;
35}
36 returnn *
factorial(n - 1);
37}
38}
// namespace math 39 44static void tests() {
45assert(
math::factorial(1) == 1);
46assert(
math::factorial(0) == 1);
47assert(
math::factorial(5) == 120);
48assert(
math::factorial(10) == 3628800);
49assert(
math::factorial(20) == 2432902008176640000);
50std::cout <<
"All tests have passed successfully!\n";
51}
52 57int main() {
58 tests();
// run self-test implementations 59 return0;
60}
testsstatic void tests()
Self-test implementations.
Definition factorial.cpp:44 mainint main()
Main function.
Definition factorial.cpp:57 mathfor assert
math::factorialuint64_t factorial(uint8_t n)
function to find factorial of given number
Definition factorial.cpp:29RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4