This will return a square root table. Square roots are rounded to 3 decimals.
<?php
/**
* GetSquareRoots()
* Return Square/Square root table
* @param mixed $start
* @param mixed $end
* @return string $Sqrt
*/
function GetSquareRoots( $start, $end )
{
// Define variable holding table
$Sqrt = '<table><tr>
<th style="width: 150px; text-align:left;">Number</th>
<th style="width: 150px; text-align:left;">Square root</th>
<th style="width: 150px; text-align:left;">Square</th>
</tr>
';
// As long $x <= $end add a new row containing a cell for square root and root
for ( $x = $start; $x <= $end; $x++ ) $Sqrt .= '<tr><td>' . $x . '</td><td>√' . $x . ' = ' . round( sqrt( $x ), 3 ) .
'</td><td>' . ( $x * $x ) . '</td></tr>';
$Sqrt .= '</table>';
// Return the table
return $Sqrt;
}
// Create table 1 - 15
echo GetSquareRoots( 1, 15 );
?>
This will output something like:
| Number | Square root | Square |
|---|---|---|
| 1 | √1 = 1 | 1 |
| 2 | √2 = 1.414 | 4 |
| 3 | √3 = 1.732 | 9 |
| 4 | √4 = 2 | 16 |
| 5 | √5 = 2.236 | 25 |
| 6 | √6 = 2.449 | 36 |
| 7 | √7 = 2.646 | 49 |
| 8 | √8 = 2.828 | 64 |
| 9 | √9 = 3 | 81 |
| 10 | √10 = 3.162 | 100 |
| 11 | √11 = 3.317 | 121 |
| 12 | √12 = 3.464 | 144 |
| 13 | √13 = 3.606 | 169 |
| 14 | √14 = 3.742 | 196 |
| 15 | √15 = 3.873 | 225 |
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)

» Latest comments