71. PHP Program to find ‘m’ power ‘n’ of given number.
How does this program work?
- This program is used to find ‘m’ power ‘n’ of given number using PHP.
- The integers entered by the user is stored in variables m,n.
- After that m will be multiplied by n times using given logic.
Here is the code
<html>
<head>
<title>PHP Program To find the m power n of a number</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num1" value="" placeholder="Enter base value"/> </td>
</tr>
<tr>
<td> <input type="text" name="num2" value="" placeholder="Enter exponent value"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$m = $_POST['num1'];
$n = $_POST['num2'];
$i = 1;
$ans = 1;
while ($i<=$n)
{
$ans = $ans*$m; //Power of number formula
$i = $i+1;
}
echo ("$m to the power $n is $ans");
return 0;
}
?>
</body>
</html>