Maplewing

1/26 PHP: evenSum

Jan 26th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.29 KB | None | 0 0
  1. <?php
  2. function evenSum($a, $b){
  3.         $total = 0;
  4.         for($i = $a; $i <= $b ; $i++){
  5.                 if($i % 2 == 0){
  6.                         $total += $i;
  7.                 }
  8.         }
  9.  
  10.         return $total;
  11. }
  12.  
  13. $a = 1;
  14. $b = 10;
  15.  
  16. $sum = evenSum($a, $b);
  17.  
  18. echo $sum;
  19.  
  20. ?>
Add Comment
Please, Sign In to add comment