Hello Friends Today, through this tutorial, I will tell you How to Write Program Complex Numbers calculator using PHP with HTML. Here’s a basic example of a complex numbers calculator using PHP and HTML:
index.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Complex Numbers Calculator</title> </head> <body> <h1>Complex Numbers Calculator</h1> <form action="" method="post"> <label for="real1">Real Part 1:</label> <input type="number" step="any" name="real1" id="real1"> <label for="imaginary1">Imaginary Part 1:</label> <input type="number" step="any" name="imaginary1" id="imaginary1"> <br> <label for="real2">Real Part 2:</label> <input type="number" step="any" name="real2" id="real2"> <label for="imaginary2">Imaginary Part 2:</label> <input type="number" step="any" name="imaginary2" id="imaginary2"> <br> <button type="submit" name="calculate">Calculate</button> </form> <br> <?php if (isset($_POST['calculate'])) { // Get the real and imaginary parts from the form $real1 = $_POST['real1']; $imaginary1 = $_POST['imaginary1']; $real2 = $_POST['real2']; $imaginary2 = $_POST['imaginary2']; // Perform addition $sum_real = $real1 + $real2; $sum_imaginary = $imaginary1 + $imaginary2; // Perform subtraction $difference_real = $real1 - $real2; $difference_imaginary = $imaginary1 - $imaginary2; // Display results echo "Sum: " . $sum_real . " + " . $sum_imaginary . "i<br>"; echo "Difference: " . $difference_real . " + " . $difference_imaginary . "i"; } ?> </body> </html>
In this example:
1. The user inputs the real and imaginary parts of two complex numbers into the form.
2. Upon submitting the form, PHP code processes the input and calculates the sum and difference of the complex numbers.
3. The results are then displayed below the form.