Homework 4 solutions

   Function Example   Counting to N by M with a function "; }

printSequence(20, 5); printSequence(10, 2); printSequence(40, 3); printSequence(100, 10); printSequence(50, 25);

/*       * printSequence2 prints either an increasing or decreasing sequence. * The default is increasing in which case $n > 0. * For decreasing sequences, $n < 0. */      function printSequence2($n, $m, $incr=TRUE) { if ($incr == TRUE) { for ($k = 0; $k <= $n; $k+=$m) echo "$k "; }        else { for ($k = 0; $k >= $n; $k-=$m) echo "$k "; }        echo ""; }

printSequence2(20, 5); printSequence2(-20, 5, FALSE);

?>  