Count digits in a factorial | Set 1 | A C ++ program to find the number of digits in a factorial ; This function receives an integer n , and returns the number of digits present in n ! ; factorial exists only for n >= 0 ; base case ; else iterate through n and calculate the value ; Driver code
using System ; class GFG { static int findDigits ( int n ) { if ( n < 0 ) return 0 ; if ( n <= 1 ) return 1 ; double digits = 0 ; for ( int i = 2 ; i <= n ; i ++ ) digits += Math . Log10 ( i ) ; return ( int ) Math . Floor ( digits ) + 1 ; } public static void Main ( ) { Console . Write ( findDigits ( 1 ) + " STRNEWLINE " ) ; Console . Write ( findDigits ( 5 ) + " STRNEWLINE " ) ; Console . Write ( findDigits ( 10 ) + " STRNEWLINE " ) ; Console . Write ( findDigits ( 120 ) + " STRNEWLINE " ) ; } }