Advertisement
dimipan80

Square Root Sum

Apr 22nd, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <!--Write a PHP script SquareRootSum.php that displays a table in your browser with 2 columns. The first column should contain a number (even numbers from 0 to 100) and the second column should contain the square root of that number, rounded to the second digit after the decimal point. The last row of the table should contain the sum of all values in the Square column. Styling the page is optional.-->
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <head lang="en">
  6.     <meta charset="UTF-8">
  7.     <title>Square Root Sum</title>
  8.     <style type="text/css">
  9.         table, th, td {
  10.             border: 1px solid #000;
  11.         }
  12.     </style>
  13. </head>
  14. <body>
  15. <table>
  16.     <thead>
  17.     <tr>
  18.         <th>Number</th>
  19.         <th>Square</th>
  20.     </tr>
  21.     </thead>
  22.     <tbody>
  23.     <?php
  24.     $sum = 0;
  25.     for ($i = 0; $i <= 100; $i += 2) {
  26.         $sqrt = (float)round(sqrt($i), 2);
  27.         $sum += $sqrt;
  28.         echo "<tr><td>$i</td><td>$sqrt</td></tr>";
  29.     }
  30.     ?>
  31.     </tbody>
  32.     <tfoot>
  33.     <tr>
  34.         <td><strong>Total:</strong></td>
  35.         <td><?= round($sum, 2) ?></td>
  36.     </tr>
  37.     </tfoot>
  38. </table>
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement