72. PHP Program to find the Power of a given number without using Multiplication.
How does this program work?
- This program is used to find the power of a given number without using multiplication using PHP.
- The integer entered by the user is stored in variable n.
- Now calculated the power of a given number without using multiplication(*) followed by below code in PHP.
Here is the code
<html>
<head>
<title>PHP Program To find the power of a given number without using *</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']))
{
$a = $_POST['num1'];
$b = $_POST['num2'];
$answer = $a;
$increment = $a;
for($i = 1; $i < $b; $i++)
{
for($j = 1; $j < $a; $j++)
{
$answer +=$increment; //By incrementing b times we get power of the value
}
$increment=$answer;
}
echo "$a to power of $b is $answer";
return 0;
}
?>
</body>
</html>