Sunday 27 March 2016

Write a JavaScript program to find the area and circumference of a circle?

Code:


<!DOCTYPE html>
<html>
<body>
<center>
<h1>Find the area and circumference of a circle</h1>
<script>
function Calculate()
{
var radius=document.form1.txtRadius.value;
document.getElementById("demo").innerHTML="The area of the circle is "+(radius*radius*Math.PI)+"<br/>The circumference of the circle is "+(2*radius*Math.PI);
}
</script>
<form name="form1">
Enter the radius of the circle: <input type="text" name="txtRadius" size="10">
<input type="button" value="Calculate" onclick="Calculate()">
</form>
<p id="demo"></p>
</center>
</body>
</html>


Output:



No comments:

Post a Comment