AnkitWebLogic

PHP - Arithmetic operator | User input

Q2. Write a program to input 2 numbers in PHP and calculate addition, subtraction, multiplication, division, modulas, power using operator 1

<html>
<body>    
    <form action="" method="get">
        <p>Enter 1st Number: <input type="text" name='a' value="<?php echo $a; ?>"></p>
        <p>Enter 2nd Number: <input type="text" name='b' value="<?php echo $b; ?>"></p>
        <button type="submit" name="submit">Submit</button>
    </form>
<?php
    if(isset($_GET['submit']))
    {
        $a=$_GET['a'];
        $b=$_GET['b'];
	
        $c=$a+$b;
        echo "Sum of $a and $b is ".$c;
    
        $d=$a-$b;
        echo "<br>Subtraction of $a and $b is ".$d;
        
        $e=$a*$b;
        echo "<br>Multiplication of $a and $b is ".$e;
        
        $f=$a/$b;
        echo "<br>Division of $a and $b is ".$f;
	    
        $g=$a%$b;
        echo "<br>Modulas of $a and $b is ".$g;
	    
        $h=$a**2;
        echo "<br>$a Power 2 is ".$h;
    }
?>
</body>
</html>

Enter 1st Number:

Enter 2nd Number: