your image

PHP Area of Triangle Program - javatpoint

javapoint
Related Topic
:- PHP Java

a

rea of Triangle

Area of a triangle is calculated by the following Mathematical formula,

  1. (base * height) / 2 = Area  

Area of Triangle in PHP

Program to calculate area of triangle with base as 10 and height as 15 is shown.

Example:

  1. <?php  
  2.  $base = 10;  
  3.  $height = 15;  
  4.  echo "area with base $base and height $height= " . ($base * $height) / 2;  
  5.  ?>  

Output:

 

C++ vs Java

Area of Triangle with Form in PHP

Program to calculate area of triangle by inserting values in the form is shown.

Example:

  1. <html>  
  2. <body>  
  3. <form method = "post">   
  4. Base: <input type="number" name="base">   
  5. <br><br>  
  6. Height: <input type="number" name="height"><br>   
  7. <input type = "submit" name = "submit" value="Calculate">   
  8. </form>   
  9. </body>   
  10. </html>  
  11. <?php   
  12. if(isset($_POST['submit']))  
  13.     {   
  14. $base = $_POST['base'];   
  15. $height = $_POST['height'];   
  16. $area = ($base*$height) / 2;   
  17. echo "The area of a triangle with base as $base and height as $height is $area";   
  18. }   
  19. ?>   

Output:

Comments