Last active
          March 29, 2017 06:16 
        
      - 
      
 - 
        
Save rmamont/e281d534ad3a63f3ef0f3588fca73f09 to your computer and use it in GitHub Desktop.  
    calc factorial in iterative method
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| function fctrl($num) { | |
| $iter = function($num, $acc) use (&$iter) { | |
| if ($num == 1) { | |
| return $acc; | |
| } | |
| return $iter($num - 1, $acc * $num); | |
| }; | |
| return $iter($num, 1); | |
| } | |
| echo fctrl(97), PHP_EOL; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment