Hướng dẫn quadratic equation 2 php - phương trình bậc hai 2 php

Tôi đã cố gắng tạo một bộ giải phương trình bậc hai trong PHP:

index.html:

<html> <body> <form action="findx.php" method="post"> Find solution for ax^2 + bx + c<br> a: <input type="text" name="a"><br> b: <input type="text" name="b"><br> c: <input type="text" name="c"><br> <input type="submit" value="Find x!"> </form> </body> </html>

findx.php:

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?>

Vấn đề là nó trả về câu trả lời sai (d là đúng, x1 và x2 không) có vẻ như sqrt () đang trả về 0 hoặc có thể là một cái gì đó khác.

Naruto

1.2103 huy hiệu vàng25 Huy hiệu bạc26 Huy hiệu đồng3 gold badges25 silver badges26 bronze badges

Hỏi ngày 16 tháng 4 năm 2015 lúc 12:39Apr 16, 2015 at 12:39

1

Có một lỗi đánh máy trong dòng này:

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 5

đang gán giá trị <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 6 cho <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 7 thay vì so sánh nó. Điều đó có nghĩa là bạn luôn đánh giá <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 8, đó là 0, trong khối <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 9 của bạn.

Nó nên là:

<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 0

Đã trả lời ngày 16 tháng 4 năm 2015 lúc 12:43Apr 16, 2015 at 12:43

1

Đầu tiên, chúng ta phải tính toán phân biệt đối xử và sau đó tìm hai giải pháp của phương trình bậc hai bằng mô -đun CMATH.

<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 6 <?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 1

Where:

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 3Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 7

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 42Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 07

Is

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 86Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 5Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 6__

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 98Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 5Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 6Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 3ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 03


Một dạng tiêu chuẩn của phương trình bậc hai là:

AX2 + BX + C = 0

<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?>

A, B và C là số thực và A ≠ 0.

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i



Rễ của phương trình là:

  • Ví dụ:
  • Rễ của phương trình x2 + 5x + 4 = 0 là
  • Rễ của phương trình sẽ là tưởng tượng nếu d = b2 - 4ac 0 $, thì rễ là có thật và khác nhau $$ x = \ frac {-b \ pm \ sqrt {b^2-4ac}} {2a}. $$ $$
# Python program to find roots of quadratic equation import math # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c # checking condition for dcriminant if d > 0: print("Your equation has real and different roots:") print((-b + math.sqrt(d))/(2 * a)) print((-b - math.sqrt(d))/(2 * a)) elif d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is less than 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", math.sqrt(-d),'i') print(- b / (2 * a), " -", math.sqrt(-d),'i') equationroots()

2. Python giải phương trình bậc hai bằng mô -đun toán học phức tạp

Đầu tiên, chúng ta phải tính toán phân biệt đối xử và sau đó tìm hai giải pháp của phương trình bậc hai bằng cách sử dụng & nbsp; ____ ____ 21 & nbsp; mô -đun.

<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 1 Mô -đun - Hàm toán học cho các số phức - & nbsp; cung cấp quyền truy cập vào các hàm toán học cho các số phức. Các hàm trong mô-đun này chấp nhận số nguyên, số dấu phẩy động hoặc số phức là đối số. Họ cũng sẽ chấp nhận bất kỳ đối tượng Python nào có phương thức <?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 3 hoặc <?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 4: các phương pháp này được sử dụng để chuyển đổi đối tượng thành số điểm phức tạp hoặc nổi, và sau đó chức năng được áp dụng cho kết quả chuyển đổi.

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()

Hình thức tiêu chuẩn của phương trình bậc hai là:

ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 0

Các giải pháp của phương trình bậc hai này được đưa ra bởi:

(-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)

Mã nguồn

# Solve the quadratic equation ax**2 + bx + c = 0 # import complex math module import cmath a = 1 b = 5 c = 6 # calculate the discriminant d = (b**2) - (4*a*c) # find two solutions sol1 = (-b-cmath.sqrt(d))/(2*a) sol2 = (-b+cmath.sqrt(d))/(2*a) print('The solution are {0} and {1}'.format(sol1,sol2))

Đầu ra

Enter a: 1 Enter b: 5 Enter c: 6 The solutions are (-3+0j) and (-2+0j)

Chúng tôi đã nhập mô -đun <?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 1 để thực hiện căn bậc hai phức tạp. Đầu tiên, chúng tôi tính toán phân biệt đối xử và sau đó tìm hai giải pháp của phương trình bậc hai.

Bạn có thể thay đổi giá trị của A, B và C trong chương trình trên và kiểm tra chương trình này.

Đưa ra một phương trình bậc hai, nhiệm vụ là giải phương trình hoặc tìm ra rễ của phương trình. Dạng tiêu chuẩn của phương trình bậc hai là -

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 0

Examples:

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 1

Phương pháp 1: Sử dụng công thức trực tiếp Using the direct formula

Sử dụng công thức bậc hai dưới đây, chúng ta có thể tìm thấy gốc của phương trình bậc hai.

Có những trường hợp quan trọng sau đây.

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 2

<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 6 <?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 7

<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 8 <?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 9

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 0Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 1Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 3Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 4 Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 3__

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 0# Python program to find roots of quadratic equation import math # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c # checking condition for dcriminant if d > 0: print("Your equation has real and different roots:") print((-b + math.sqrt(d))/(2 * a)) print((-b - math.sqrt(d))/(2 * a)) elif d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is less than 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", math.sqrt(-d),'i') print(- b / (2 * a), " -", math.sqrt(-d),'i') equationroots() 3Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 # Python program to find roots of quadratic equation import math # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c # checking condition for dcriminant if d > 0: print("Your equation has real and different roots:") print((-b + math.sqrt(d))/(2 * a)) print((-b - math.sqrt(d))/(2 * a)) elif d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is less than 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", math.sqrt(-d),'i') print(- b / (2 * a), " -", math.sqrt(-d),'i') equationroots() 5# Python program to find roots of quadratic equation import math # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c # checking condition for dcriminant if d > 0: print("Your equation has real and different roots:") print((-b + math.sqrt(d))/(2 * a)) print((-b - math.sqrt(d))/(2 * a)) elif d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is less than 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", math.sqrt(-d),'i') print(- b / (2 * a), " -", math.sqrt(-d),'i') equationroots() 6# Python program to find roots of quadratic equation import math # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c # checking condition for dcriminant if d > 0: print("Your equation has real and different roots:") print((-b + math.sqrt(d))/(2 * a)) print((-b - math.sqrt(d))/(2 * a)) elif d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is less than 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", math.sqrt(-d),'i') print(- b / (2 * a), " -", math.sqrt(-d),'i') equationroots() 7

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 0# Python program to find roots of quadratic equation import math # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c # checking condition for dcriminant if d > 0: print("Your equation has real and different roots:") print((-b + math.sqrt(d))/(2 * a)) print((-b - math.sqrt(d))/(2 * a)) elif d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is less than 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", math.sqrt(-d),'i') print(- b / (2 * a), " -", math.sqrt(-d),'i') equationroots() 9 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 0<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 6# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 2

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 3# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 5# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 6# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 7

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 3# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 00Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 6Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 3ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 03

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 3# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 00Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 6Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 3___

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 0# Solve the quadratic equation ax**2 + bx + c = 0 # import complex math module import cmath a = 1 b = 5 c = 6 # calculate the discriminant d = (b**2) - (4*a*c) # find two solutions sol1 = (-b-cmath.sqrt(d))/(2*a) sol2 = (-b+cmath.sqrt(d))/(2*a) print('The solution are {0} and {1}'.format(sol1,sol2)) 3 Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 1Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 6# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 2

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 3# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 5Enter a: 1 Enter b: 5 Enter c: 6 The solutions are (-3+0j) and (-2+0j)2# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 7

Các

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 0<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 9<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 06

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 3# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 5<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 10# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 7

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 3# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 55____36

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 3# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 55____36

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 9Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 38

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 3Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 41

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 42Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 6<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 45

# Python program to find roots of quadratic equation import math # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c # checking condition for dcriminant if d > 0: print("Your equation has real and different roots:") print((-b + math.sqrt(d))/(2 * a)) print((-b - math.sqrt(d))/(2 * a)) elif d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is less than 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", math.sqrt(-d),'i') print(- b / (2 * a), " -", math.sqrt(-d),'i') equationroots() 9 Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 9Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 6# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 2

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 3# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 5<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 55# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 7

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 9<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 06

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 0<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 60

Output:

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 3

Phương pháp 2: Sử dụng mô -đun toán học phức tạp Using the complex math module

Đầu tiên, chúng ta phải tính toán phân biệt đối xử và sau đó tìm hai giải pháp của phương trình bậc hai bằng mô -đun CMATH.

<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 6 <?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 1

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 9Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 38

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 3Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 41

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 42Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 6<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 45

# Python program to find roots of quadratic equation import math # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c # checking condition for dcriminant if d > 0: print("Your equation has real and different roots:") print((-b + math.sqrt(d))/(2 * a)) print((-b - math.sqrt(d))/(2 * a)) elif d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is less than 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", math.sqrt(-d),'i') print(- b / (2 * a), " -", math.sqrt(-d),'i') equationroots() 9 Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 9Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 2 <?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 6# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 2

Equation is x*x+5x+4=0 Roots are: -1, -4 Equation is x*x+4x+5=0 Roots are: -2 ± 1 i 0<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 60

Phương pháp 2: Sử dụng mô -đun toán học phức tạp

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 5<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 12<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 13

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 15

# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() 4<?php function roots($a, $b, $c) { $D = $b*$b - 4*$a*$c; if ($D >= 0){ $x1 = (-$b + sqrt($D))/(2*$a); $x2 = (-$b - sqrt($D))/(2*$a); echo "Roots are: $x1, $x2 \n"; } else { $x1 = -$b/(2*$a); $x2 = sqrt(-$D)/(2*$a); echo "Roots are: $x1 ± $x2 i \n"; } } echo "Equation is x*x+5x+4=0\n"; roots(1,5,4); echo "\nEquation is x*x+4x+5=0\n"; roots(1,4,5); ?> 17

Output:

<?php if(isset($_POST['a'])){ $a = $_POST['a']; } if(isset($_POST['b'])){ $b = $_POST['b']; } if(isset($_POST['c'])){ $c = $_POST['c']; } $d = $b*$b - 4*$a*$c; echo $d; if($d < 0) { echo "The equation has no real solutions!"; } elseif($d = 0) { echo "x = "; echo (-$b / 2*$a); } else { echo "x1 = "; echo ((-$b + sqrt($d)) / (2*$a)); echo "<br>"; echo "x2 = "; echo ((-$b - sqrt($d)) / (2*$a)); } ?> 4

Bài Viết Liên Quan

Toplist

Bài mới nhất

Chủ đề