Recent Posts

JavaScript: Giải phương trình bậc hai Ax2 + Bx + C = 0

-

<html>
<head>
<title>Giai phuong trinh bac 2</title>
<script language="JavaScript">
function giai(form){
var x1,x2;
var x,y,z,delta;
x= parseInt(form.a.value);
y= parseInt(form.b.value);
z= parseInt(form.c.value);
delta=(y*y-4*x*z)
if(delta ==0){
alert("phuong trinh co nghiem kep");
x1=-y/(2*x) ;
x2=-y/(2*x);
form.x.value=eval(x1);
form.y.value=eval(x2);
}
else if(delta<0){
alert("phuong trinh vo nghiem");

else{
alert("phuong trinh co hai nghiem");
x1=(-y-Math.sqrt(delta))/(2*x);
x2=(-y+Math.sqrt(delta))/(2*x);
form.x.value=eval(x1);
form.y.value=eval(x2);
}
}
</script>
</head>
<body>
<form method="post">
<center>
<br>Nhap gia tri a:
<input type="text" name="a" value="">
<br> Nhap gia tri b:
<input type="text" name="b" value="">
<br>Nhap gia tri c:
<input type="text" name="c" value="">
<br>Đáp số:
<input type="text" name="x" value="">
<input type="text" name="y" value="">
<input type="button" value="giai" onClick="giai(this.form)">
</center>
</form>
</body>
</html>
[Download Mã nguồn: Chờ 5s, sau đó nhấn SKIP AD (để bỏ qua Quảng cáo)]




Klik untuk melihat kode: :) =( :s :D :-D ^:D ^o^ 7:( :Q :p T_T @@, :-a :W *fck* x@