Quangthjeugia
New Member
Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function quad(form) {
a=eval(form.a.value);
b=eval(form.b.value);
c=eval(form.c.value);
x1=-b/2/a+Math.pow(Math.pow(b,2)-4*a*c,0.5)/2/a;
x2=-b/2/a-Math.pow(Math.pow(b,2)-4*a*c,0.5)/2/a;
form.x1.value = x1;
form.x2.value = x2;
if (form.x1.value == "NaN") form.x1.value="Phương trình này vô nghiệm";
if (form.x2.value == "NaN") form.x2.value="Phương trình này vô nghiệm";
}
// End -->
</SCRIPT>
<center>
<form name=form>
<table border=1 cellpadding=2>
<tr>
<td colspan=2 align=center><b>Phương trình bậc hai<br>AX² + BX + C = 0</b></td>
</tr>
<tr>
<td>
<center><table border=1 width=100% cellpadding=2>
<tr>
<td align=center><b>A = </b></td>
<td align=center><input type=text size=6 name="a"></td>
</tr>
<tr>
<td align=center><b>B = </b></td>
<td align=center><input type=text size=6 name="b"></td>
</tr>
<tr>
<td align=center><b>C = </b></td>
<td align=center><input type=text size=6 name="c"></td>
</tr>
</tr>
</table>
</td>
<td>
<center><table border=1 width=100% cellpadding=2>
<tr>
<td colspan=2 align=center>
<input type=button value="Giải" onClick="quad(this.form)"></td>
</tr>
<tr>
<td align=center><b>X1 = </b></td>
<td align=center><input type=text size=6 name="x1"></td>
</tr>
<tr>
<td align=center><b>X2 = </b></td>
<td align=center><input type=text size=6 name="x2"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
----------> Bổ sung bài viết lúc 20:20 <----------> Bài viết trước lúc 20:19 <----------
demo