Guest User

Untitled

a guest
May 24th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <?php
  2. class FactorielCalculator {
  3.  
  4. public function calculate() {
  5. if(($n = (int)func_get_arg(0)) <= 0)
  6. throw new Exception ("Invalid argument supplied for method calculate!");
  7.  
  8. $result = 1;
  9. $range = range(1, $n);
  10. foreach($range as $current)
  11. $result = $this->multiply ($result, $current);
  12.  
  13. return $result;
  14. }
  15.  
  16. private function multiply($left, $right) {
  17. return $left * $right;
  18. }
  19. }
  20.  
  21. $factoriel = new FactorielCalculator();
  22. echo $factoriel->calculate(1500);
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment