Find sum of digits in factorial of a number | C # program to find sum of digits in factorial of a number ; Function to multiply x with large number stored in vector v . Result is stored in v . ; Calculate res + prev carry ; updation at ith position ; Returns sum of digits in n ! ; One by one multiply i to current vector and update the vector . ; Find sum of digits in vector v [ ] ; Driver code
using System ; using System . Collections ; class GFG { static ArrayList v = new ArrayList ( ) ; static void multiply ( int x ) { int carry = 0 ; int size = v . Count ; for ( int i = 0 ; i < size ; i ++ ) { int res = carry + ( int ) v [ i ] * x ; v [ i ] = res % 10 ; carry = res / 10 ; } while ( carry != 0 ) { v . Add ( carry % 10 ) ; carry /= 10 ; } } static int findSumOfDigits ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) multiply ( i ) ; int sum = 0 ; int size = v . Count ; for ( int i = 0 ; i < size ; i ++ ) sum += ( int ) v [ i ] ; return sum ; } static void Main ( ) { int n = 1000 ; Console . WriteLine ( findSumOfDigits ( n ) ) ; } }