Print factorials of a range in right aligned format | PHP 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
< ? php function find_factorial ( $ num1 , $ num2 ) { $ vec ; $ t = 0 ; $ fac = 1 ; $ 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 ) { $ x = count ( $ result ) ; $ digits = strlen ( ( string ) $ result [ $ x - 1 ] ) ; for ( $ i = 0 ; $ i < $ x ; $ i ++ ) { echo str_pad ( $ result [ $ i ] , ( $ digits + 1 ) , " " , ▁ STR _ PAD _ LEFT ) ▁ . ▁ " " } } $ m = 10 ; $ n = 20 ; $ result_fac ; $ result_fac = find_factorial ( $ m , $ n ) ; print_format ( $ result_fac ) ; ? >