Practical 5 ( Mathematical Calculation )

 

Practical No.5

Aim:

Write a PHP program for mathematical calculation.

PROGRAM:

<?php

$res = "";

if(isset($_POST['disp']))

{$f = $_POST['f'];

$s = $_POST['s'];

$ch = $_POST['ch'];

switch($ch)

{case 'ADDITION':

$res = $f + $s;

break;

case 'SUBTRACTION':

$res = $f - $s;

break;

case 'MULTIPLICATION':

$res = $f * $s;

break;

case 'DIVISION':

if($s != 0) $res = $f / $s;

else

$res = "Error";

break;

}}?>

<html>

<body>

<form action="" method="post"> <br><center><u><h1>Mathematical calculator</h1></u></center>

<br><table bgcolor="yellow" table align="center" table border="3" width="20">

<br><tr bgcolor="green"><td align="center" colspan="2">

<font color="white" face="arial black" size="5">CALCULATOR</font></td></tr>

<tr><td><input type="button" value="Enter First Input "></td>

<td><input type="text" name="f"></td></tr>

<tr><td><input type="button" value="Enter Second Input"></td>

<td><input type="text" name="s"></td></tr>

<tr><td><input type="button" value="select your option"></td>

<td><center><select name="ch">

<option>ADDITION</option> <option>SUBTRACTION</option> <option>MULTIPLICATION</option> <option>DIVISION</option>

</select></center></td></tr>

<tr><td><input type="submit" value=" RESULT " name="disp"></td>

<td><input type="text" value="<?php echo$res;?>"readonly="true">

</td></tr></table> </form> </body> </html>




Comments

Popular posts from this blog

Practical No.1

Practical 8 ( Recursive Function. )