Print factorials of a range in right aligned format | Javascript Program to print format of factorial ; vector for store the result ; variable for store the each number factorial ; copy of first number ; found first number factorial ; push the first number in result vector ; incerement the first number ; found the all reaming number factorial loop is working until all required number factorial founded ; store the result of factorial ; incerement the first number ; return the result ; function for print the result ; setw ( ) is used for fill the blank right is used for right justification of data ; number which found the factorial of between range ; store the result of factorial ; function for found factorial ; function for print format
function find_factorial ( num1 , num2 ) { let vec = [ ] ; let t = 0 ; let fac = 1 ; let temp = num1 ; while ( 1 ) { if ( temp == 1 ) break ; fac *= temp ; temp -- ; } vec [ t ++ ] = fac ; num1 ++ ; while ( num1 <= num2 ) { fac *= num1 ; vec [ t ++ ] = fac ; num1 ++ ; } return ( vec ) ; } function print_format ( result ) { let x = result . length ; let digits = String ( result [ x - 1 ] ) . length ; for ( let i = 0 ; i < x ; i ++ ) { result [ i ] = new Array ( x - i ) . fill ( " " ) . join ( " " ) + result [ i ] ; document . write ( String ( result [ i ] ) + " " ) ; } } let m = 10 ; let n = 20 ; let result_fac ; result_fac = find_factorial ( m , n ) ; print_format ( result_fac ) ;