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