| CS 199 | Willamette University | Spring, 2019 |
|
Programming in PHP, Databases with MySQL, and Web Applications |
||
We will be using with Chars(characters) and nested loops.
Write a for loop that prints out numbers from -7 to +7 inclusive.
Consider the following code segment:
for ($row = 1; $row < 4; $row++) {
for ($column = 1; $column <= $row; $column++) {
echo " * ";
}
echo "<br />";
}
Create a nested for loop that prints out row numbers 1 through 5 rather than the asterisks in the previous problem. The output should have the form:
1 22 333 4444
Create a nested for loop that prints out a checkered board.
Hints:
Consider this code segment:
$row = 1;
$col = 1;
while( $row < 3 )
{
while( $col < 3 )
{
echo ":) ";
$col++;
}
echo "<br />";
$row++;
}
Printing box shapes
From the previous lab, you created a table that produced a table of monthly balances
Using the same equation for monthly rate, interest and new balance, create similar tables, but continue the printout until the bank balance doubles.
Revise the previous problem, so that it prints just the interest rate and the number of months to double, for interest rates of 5%, 6%, through 12%.
Hint: Go through the work of what you just did, but do not print every month, but instead just print the total number of months after it is doubled.
As an example, the output might begin as follows:
Interest Months
Rate to Double
0.05 167
0.06 139
0.07 120
... ...
|
created 5 February 2019 by Saniya Lakka revised 5-10 February 2019 by Saniya Lakka, with minor reformatting and editing by Henry M. Walker |
|