TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
check_factorial.cpp File Reference

A simple program to check if the given number is a factorial of some number or not. More...

#include <cassert>
#include <cstdint>
#include <iostream>
Include dependency graph for check_factorial.cpp:

Go to the source code of this file.

Namespaces

namespace  math
 for assert
 

Functions

bool math::is_factorial (uint64_t n)
 Function to check if the given number is factorial of some number or not.
 
static void tests ()
 Self-test implementations.
 
int main ()
 Main function.
 

Detailed Description

A simple program to check if the given number is a factorial of some number or not.

A factorial number is the sum of k! where any value of k is a positive integer. https://www.mathsisfun.com/numbers/factorial.html

Author
Divyajyoti Ukirde
ewd00010

Definition in file check_factorial.cpp.

Function Documentation

◆ main()

int main ( void )

Main function.

Returns
0 on exit

Definition at line 71 of file check_factorial.cpp.

71 {
72 tests(); // run self-test implementations
73 return 0;
74}
static void tests()
Self-test implementations.

◆ tests()

static void tests ( )
static

Self-test implementations.

Returns
void

Definition at line 56 of file check_factorial.cpp.

56 {
57 assert(math::is_factorial(50) == false);
58 assert(math::is_factorial(720) == true);
59 assert(math::is_factorial(0) == false);
60 assert(math::is_factorial(1) == true);
61 assert(math::is_factorial(479001600) == true);
62 assert(math::is_factorial(-24) == false);
63
64 std::cout << "All tests have successfully passed!" << std::endl;
65}
bool is_factorial(uint64_t n)
Function to check if the given number is factorial of some number or not.