主要内容
- 1.规则多边形已知边数计算内角
- 2.规则多边形已知边数计算外角
- 3.规则多边形已知外角求边数
- 4.已知数字计算罗马数字
- 5.已知三个顶点计算三角形的面积
- 6.判断一个数是不是素数
1.规则多边形已知边数计算内角
function side(n) {
var edgeNum = ((n - 2) * 180) / n;
var inner = 180 - document.form1.intx.value;
var outer = n*document.form1.intx.value;
}
2.规则多边形已知边数计算外角
function extn(edgeNum) {
var inner = 360 / e;
var outer = 180 - e;
}
3.规则多边形已知外角求边数
function intn(i) {
var inner= 180 - i;
var outter = 360 / (180 - i);
}
4.已知数字计算罗马数字
var ones_numerals = new Array();
ones_numerals[0] = "";
ones_numerals[1] = "I";
ones_numerals[2] = "II";
ones_numerals[3] = "III";
ones_numerals[4] = "IV";
ones_numerals[5] = "V";
ones_numerals[6] = "VI";
ones_numerals[7] = "VII";
ones_numerals[8] = "VIII";
ones_numerals[9] = "IX";
var tens_numerals = new Array();
tens_numerals[0] = "";
tens_numerals[1] = "X";
tens_numerals[2] = "XX";
tens_numerals[3] = "XXX";
tens_numerals[4] = "XL";
tens_numerals[5] = "L";
tens_numerals[6] = "LX";
tens_numerals[7] = "LXX";
tens_numerals[8] = "LXXX";
tens_numerals[9] = "XC";
var hundreds_numerals = new Array();
hundreds_numerals[0] = "";
hundreds_numerals[1] = "C";
hundreds_numerals[2] = "CC";
hundreds_numerals[3] = "CCC";
hundreds_numerals[4] = "CD";
hundreds_numerals[5] = "D";
hundreds_numerals[6] = "DC";
hundreds_numerals[7] = "DCC";
hundreds_numerals[8] = "DCCC";
hundreds_numerals[9] = "CM";
var thousands_numerals = new Array();
thousands_numerals[0] = "";
thousands_numerals[1] = "M";
thousands_numerals[2] = "MM";
thousands_numerals[3] = "MMM";
function checkNumber(number) {
if ((parseInt(number) < 4000) && (parseInt(number) > 0)) {
var numeral = createNumeral(number);
if (numeral.indexOf('undefined') == -1) {
window.document.form.numeral.value = numeral;
}
} else {
alert('請輸入一個有效的數字。');
}
}
function createNumeral(num) {
var new_num = num
var thousands = Math.floor(new_num / 1000);
new_num -= thousands * 1000;
var hundreds = Math.floor(new_num / 100);
new_num -= hundreds * 100;
var tens = Math.floor(new_num / 10);
new_num -= tens * 10;
var ones = Math.floor(new_num / 1);
if ((thousands == NaN) || (hundreds == NaN) || (tens == NaN) || (ones == NaN)) {
alert('you must enter a valid number');
} else {
var array = new Array(thousands, hundreds, tens, ones);
return makeNumeral(array);
}
}
function makeNumeral(place_values) {
var numeral = "";
numeral += thousands_numerals[place_values[0]];
numeral += hundreds_numerals[place_values[1]];
numeral += tens_numerals[place_values[2]];
numeral += ones_numerals[place_values[3]];
return numeral;
}
5.已知三个顶点计算三角形的面积
function triangle(form) {
var x1 = eval(form.x1.value);
var y1 = eval(form.y1.value);
var x2 = eval(form.x2.value);
var y2 = eval(form.y2.value);
var x3 = eval(form.x3.value);
var y3 = eval(form.y3.value);
form.answer.value = ((x1 * y2 + x2 * y3 + x3 * y1) - (x2 * y1 + x3 * y2 + x1 * y3)) / 2;
}
6.判断一个数是不是素数
function prime(form) {
var num = parseInt(form.number.value);
if (isNaN(num) || num < 0) {
form.result.value = (form.number.value + " is not a valid number! Try again!");
}
if (num == 1 || num == 2) {
form.result.value = (num + " is prime!");
}
for (var i = 2; i < num; i++) {
if (num % i == 0) {
var prime = "yes";
form.result.value = (num + " is not prime. It is divisible by " + i + ".");
break;
}
if (num % i != 0) var prime = "no";
}
if (prime == "no") form.result.value = (num + " is prime!");
}
欢迎扫码关注我: