Mathamatical Power function in Php without using pow()


 <html>
<head>
 <title>Power function</title>
 <style>
 #Sbutton
 {
 margin-right: 40px;

 }
 input[type="text"]
 {
 margin-bottom:5px;
 display: block;
 }
 h1
 {
 text-align: center;
 }

 </style>
</head>
<body>
<h1>Power Function</h1>
 <form action="pow.php" method="post">
 <input type="text" name="txtBase" placeholder="Enter Base">
 <input type="text" name="txtExponent" placeholder="Enter Exponent">
 <input type="submit" name="txtSubmit" id="Sbutton">

 </form>
</body>

</html>
<?php
if(isset($_POST['txtSubmit']))
{
 $Base = $_POST['txtBase'];//Base textfield name
 $Exp = $_POST['txtExponent'];//Exponent textfield name
 power($Base,$Exp);
}
function power($Base,$Exp)
{
 $A=$Base;
 for($a=1;$a<$Exp;$a++)
 {
 $A=$A*$Base;
 echo "$Base x ";
 }
 echo "$Base = $A";
}

?>
Advertisements

It's Great To Hear From You

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s