Count factorial numbers in a given range | Program to count factorial numbers in given range ; Function to count factorial ; Find the first factorial number ' fact ' greater than or equal to ' low ' ; Count factorial numbers in range [ low , high ] ; Return the count ; Driver program to test above function
#include <iostream> NEW_LINE using namespace std ; int countFact ( int low , int high ) { int fact = 1 , x = 1 ; while ( fact < low ) { fact = fact * x ; x ++ ; } int res = 0 ; while ( fact <= high ) { res ++ ; fact = fact * x ; x ++ ; } return res ; } int main ( ) { cout << " Count ▁ is ▁ " << countFact ( 2 , 720 ) ; return 0 ; }