欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實現(xiàn)簡單的二元方程計算器功能示例

 更新時間:2017年01月03日 10:45:43   作者:Alixixi  
這篇文章主要介紹了JS實現(xiàn)簡單的二元方程計算器功能,涉及javascript數(shù)學運算相關操作技巧,需要的朋友可以參考下

本文實例講述了JS實現(xiàn)簡單的二元方程計算器功能。分享給大家供大家參考,具體如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>二元方程</TITLE>
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var rootparti;
var rootpart;
var det;
var rootparti1;
var rootparti2;
var a;
var b;
var c;
var x1;
var x2;
var i = "i";
function 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 = "Not a quadratic equation, but here is your answer for x";
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
else if (a == "" && c != 0) {
x1 = -c / b;
x2 = "Not a quadratic equation";
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
else {
quad();
  }
}
function 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 = rootparti;
rootparti2 = (-1 * parseFloat(rootparti)) + i;
}
else {
rootparti1 = (-1 * parseFloat(rootparti)) + i;
rootparti2 = rootparti;
}
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 = rootparti1;
x2 = rootparti2;
}
else {
x1 = (-b / (2 * a) + " + " + rootparti1);
x2 = (-b / (2 * a) + " + " + rootparti2);
}
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
// End -->
</script>
<form name=fquad>
 <table align="center">
  <tr>
<td>
<h2>
<input name=fa size=4>
 <font color="#33FF33">x<SUP>2</SUP>+</font> 
 <input name=fb size=4>
 <font color="#33FF33"> x +</font> 
 <input name=fc size=4>
 <font color="#33FF33">= 0</font> 
 <input type=button value="求值" onClick="checkQuad()">
 <input type=reset value="重填">
</h2>
</td>
</tr>
<tr>
<td>
<h2> <font color="#33FF33">x<sub>1</sub>=</font>
<input name=x1 size=45>
 <font color="#33FF33">x<sub>2</sub>= </font>
<input name=x2 size=45>
</h2>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>

PS:這里再為大家推薦幾款計算工具供大家進一步參考借鑒:

在線一元函數(shù)(方程)求解計算工具:
http://tools.jb51.net/jisuanqi/equ_jisuanqi

科學計算器在線使用_高級計算器在線計算:
http://tools.jb51.net/jisuanqi/jsqkexue

在線計算器_標準計算器:
http://tools.jb51.net/jisuanqi/jsq

更多關于JavaScript相關內(nèi)容感興趣的讀者可查看本站專題:《JavaScript數(shù)學運算用法總結》、《JavaScript數(shù)據(jù)結構與算法技巧總結》、《JavaScript數(shù)組操作技巧總結》、《JavaScript排序算法總結》、《JavaScript遍歷算法與技巧總結》、《JavaScript查找算法技巧總結》及《JavaScript錯誤與調(diào)試技巧總結

希望本文所述對大家JavaScript程序設計有所幫助。

相關文章

最新評論