3. PHP Program to find the Square and Cube of a given number.
How does this program work?
- In this program you will learn about how to do Mathematical functions using PHP.
- This program will helpful to calculate square and cube of a number.
- And then by using the given formula you will get output.
Here is the code
<html>
<head>
<title>PHP Program To find Square and Cube of a number</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td><input type="text" name="num1" value="" placeholder="Enter a value"/></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"/></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$a = $_POST['num1'];
$square = $a * $a; // Square of a number
$cube = $a * $a * $a; //Cube of a number
echo "Square of number " .$a." is "." = ".$square;
echo "Cube of number " .$a." is "." = ".$cube;
return 0;
}
?>
</body>
</html>