JavaScript代码求老师帮忙
script language="javascript"
var n=new Number(3.1415926);
n.toFixed(2);
/仿氏贺/面积
function yuanMj(r){
return n*r*r;
}
//周长
function yuanZc(r){
return 2*n*r;
}
var r=parseInt(prompt("请输入圆的半径",""));
document.write("请备派输入圆的半径: "+r+"br");
var area= new Number(yuanMj(r)); //修改第1处
document.write("圆的面积是: "+area.toFixed(2)+"br核漏");
var zhouc= new Number(yuanZc(r)); //修改第2处
document.write("圆的周长是: "+zhouc.toFixed(2));
/script
javascript写已知圆的半径为2.5CM,求出该圆的直径、周长和面积
html
head消薯
script type="text/javascript"
radius=2.5;
diameter=radius*2;
pi=Math.PI;
circumference=pi*diameter;
circleArea=pi*radius*radius;
document.write("半径为"+radius+"厘米的圆,直径为"+diameter+"厘米,周长为"+circumference+"厘米销桥猜,面积为"+circleArea+"平方亏型厘米。");
/script
/head
body
/body
/html
javascript随机产生1~20之间的半径,然后计算圆的周长与面积函数,周长与面积的
!doctype html
html
head
titleCZT4-3/title
/head
script
function randomR( )
{
var m=Math.floor(Math.random()*20)+1;
document.myform.r.value=m;
}
function compute( )
{
var radius=document.myform.r.value;
if (isNaN(radius)==false radius.length!=0)
{
var C,S;
C=2*Math.PI*parseFloat(radius);
S=Math.PI*Math.pow(radius,2);
C=Math.round(C*100)/100;
S=Math.round(S*100)/100;
document.myform.c.value=C;
document.myform.s.value=S;
}
else
alert("请输入半径,必须为明颂数字!");
}
/script
body
form name="myform" id="激厅郑myform"
半径:input name="r" type="text" br
周长:input name="c" type="text" br
面积:input name="s" type="text" br
input name="calC" type="button" value="随机半径" onClick="randomR( )"
input name="calS" type="button"伏孙 value="计算结果" onClick="compute( )"
/form
/body
/html
javascript求圆周长和面积 2、 自定义一个circle对象,其属性r为圆的半径,方法Area的作用是求该圆的面积
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/橘猛html; charset=utf-8" /
title计算出圆的周长和面积/title
script language="javascript"
function circle(r)
{
this.r=r
this.Area=Area
this.Circum=Circum
}
function Circum()
{
return(3.14*2*this.r)
}
function Area()
{
return(3.14*this.r*this.r)
}
r=parseInt(prompt("请输入半径:",""));
var newcircle=new circle(r)
var Circumcapital=newcircle.Circum
var Areacapital=newcircle.Area
document.write("周长:"+newcircle.Circum+"键乎br")
document.write("面积:"+newcircle.Area+"br")
/script
/head
body
/body
/html圆亮桥
怎样用javascript求圆的面积和周长
//四舍五入
function round(number, X) {
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
var r = Number(prompt('樱尘请输入圆的半径'));
if(!isNaN(r)) {
var m = round(Math.PI * Math.pow(r, 2), 2);
var c = round(2 * Math.PI * r);
alert('面枯颂燃积='没虚 + m + '\n' + '周长=' + c);
} else {
alert('请输入数字!');
}