Write a program to calculate the value of (a+b)2 in Php

Write a program to calculate the value of the given expression: (a+b)2. Take the values of a, b as input from the html.

Example

$x = ($a*$a) + ($b*$b) + (2*$a*$b);
echo $x;

Html

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>(a+b)2 in php</title>
</head>
<body>
<form method="post" action="calculate.php">
	<p><input type="number" name="a" placeholder="Enter a"></p>
	<p><input type="number" name="b" placeholder="Enter b"></p>
	<p><button name="submit">Get Value</button></p>
</form>
</body>
</html>

Php

<?php
if(isset($_POST['submit'])) {
	$a = $_POST['a'];
	$b = $_POST['b'];

	$x = ($a*$a) + ($b*$b) + (2*$a*$b);

	echo $x;
}
?>

kabeer

Added  Jun 21, 08:00 pm

Article tags

Php
×
Google login
SignUp with Email
X