text: Check if a given number is factorial of any number | C ++ implementation for the above approach ; Function to check if the given number is a factorial of any number ; Driver Code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; bool isFactorial ( int n ) { for ( int i = 1 ; ; i ++ ) { if ( n % i == 0 ) { n /= i ; } else { break ; } } if ( n == 1 ) { return true ; } else { return false ; } } int main ( ) { int n = 24 ; bool ans = isFactorial ( n ) ; if ( ans == 1 ) { cout << " Yes STRNEWLINE " ; } else { cout << " No STRNEWLINE " ; } return 0 ; }