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 <iostream>`
Include dependency graph for check_factorial.cpp:

## Functions

bool | is_factorial (uint64_t n)
void | tests ()
int | main ()

## Detailed Description

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

Author
  Divyajyoti Ukirde

## Function Documentation

## is_factorial()

bool is_factorial | ( | uint64_t | n | ) |

Function to check if the given number is factorial of some number or not.

Parameters

  n | number to be checked.

Returns
  if number is a factorial, returns true, else false.

{
if (n <= 0) {
return false;
}
for (uint32_t i = 1;; i++) {
if (n % i != 0) {
break;
}
n = n / i;
}
if (n == 1) {
return true;
} else {
return false;
}
}

## main()

int main | ( | void |  | ) |

Main function

Returns
  0 on exit

{
tests();
return 0;
}
tests
void tests()
Definition: check_factorial.cpp:36
Here is the call graph for this function:

## tests()

void tests | ( |  | ) |

Test function

Returns
  void

{
std::cout << "Test 1:\t n=50\n";
assert(is_factorial(50) == false);
std::cout << "passed\n";
std::cout << "Test 2:\t n=720\n";
assert(is_factorial(720) == true);
std::cout << "passed\n";
std::cout << "Test 3:\t n=0\n";
assert(is_factorial(0) == false);
std::cout << "passed\n";
std::cout << "Test 4:\t n=479001600\n";
assert(is_factorial(479001600) == true);
std::cout << "passed\n";
std::cout << "Test 5:\t n=-24\n";
assert(is_factorial(-24) == false);
std::cout << "passed\n";
}
std::cout
is_factorial
bool is_factorial(uint64_t n)
Definition: check_factorial.cpp:16
Here is the call graph for this function: