次のようにコードをコピーします。
<html>
<頭>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8">
<title>オンライン二次方程式計算機</title>
</head>
<本文>
<form name="fquad">
<p align="center">二次方程式を解く<br>
</p>
<テーブル align="center">
<本体>
<tr>
<td bgcolor="#990000">
<h2><font color="#ffffff"><input size="4" name="fa" type="text"> x<sup>2</sup>+ <input size="4" name=" fb" type="text"> x + <input size="4" name="fc" type="text"> = 0 <input onclick="checkQuad()" type="button" value="ソリューション" > <input type="reset" value="リセット"> </font></h2>
<p align="center"><font color="#ffffff" face="Arial"><b>二次方程式の解</b></font></p>
</td>
</tr>
<tr>
<td bgcolor="#990000">
<h2><font color="#ffffff">x<sub><a style="text-decoration: none" ><font color="#ffffff">1</font></a></sub> =<input size="45" name="x1" type="text"> <br>
x<sub>2</sub>=<input size="45" name="x2" type="text"> </font></h2>
</td>
</tr>
<tr>
</tr>
</tbody>
</テーブル>
</form>
<p align="center">CRoot 製</p>
<スクリプト言語="JavaScript">
<!--
var rootparti;
var ルートパート;
var det;
var rootparti1;
var rootparti2;
変数a;
変数 b;
変数c;
varx1;
varx2;
var i = "i";
関数 checkQuad() {
var a = document.fquad.fa.value;
var b = document.fquad.fb.value;
var c = document.fquad.fc.value;
if (a == 0 && c != 0) {
x1 = -c/b;
x2 = "二次方程式ではありませんが、x の答えは次のとおりです。";
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
else if (a == "" && c != 0) {
x1 = -c/b;
x2 = "二次方程式ではありません";
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
それ以外 {
クワッド();
}
}
関数quad() {
var a = document.fquad.fa.value;
var b = document.fquad.fb.value;
var c = document.fquad.fc.value;
det = Math.pow(b,2) - 4 * a * c;
rootpart = Math.sqrt(det) / (2 * a);
rootparti = (Math.sqrt(-det) / (2 * a)) + i;
if (parseFloat(rootparti) < 0) {
rootparti1 = ルートパート;
rootparti2 = (-1 * parseFloat(rootparti)) + i;
}
それ以外 {
rootparti1 = (-1 * parseFloat(rootparti)) + i;
rootparti2 = ルートパート;
}
if (rootparti1 == "1i") {
rootparti1 = i;
rootparti2 = "-i";
}
else if (rootparti1 == "-1i") {
rootparti1 = "-i";
rootparti2 = i;
}
if (det == 0) {
x1 = x2 = -b / (2 * a);
}
else if (det > 0) {
x1 = (-b + Math.sqrt(det)) / (2 * a);
x2 = (-b - Math.sqrt(det)) / (2 * a);
}
else if ((-b / (2 * a)) == 0) {
x1 = ルートパート 1;
x2 = ルートパート 2;
}
それ以外 {
x1 = (-b / (2 * a) + " + " + rootparti1);
x2 = (-b / (2 * a) + " + " + rootparti2);
}
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
// 複素数を解きます
// -->
</script>
</body>
</html>