Open In App

JavaScript program to find area of a circle

Improve
Improve
Like Article
Like
Save
Share
Report

Given the radius of a circle, find the area of that circle. The area of a circle can simply be evaluated using the following formula:

Area of circle

Where r is the radius of the circle and it may be in float because the value of the pie is 3.14

Approach: Using the given radius, find the area using the above formula: (pi * r * r) and print the result in float.

Example: Below is the example that will illustrate the program to find area of a circle:

Javascript




<script>
    let pi = 3.14159265358979323846;
 
    // Function to calculate the area of circle
    function findArea(r) {
        return (pi * r * r);
    }
 
    // Driver code
    let r, Area;
    r = 5;
 
    // Function calling
    Area = findArea(r);
 
    // displaying the area
    console.log("Area of Circle is: " + Area);
</script>


Output:

Area of Circle is: 78.53981633974483

Time Complexity: O(1).
Auxiliary Space: O(1), since no extra space has been taken.

Another Approach: Using Math.Pi

We can get the value of pi using the Math module in javascript

Below is the Implementation:

Javascript




<script>
 
  function findArea(r) {
          let pie_value = Math.PI;
          return (pie_value * r * r);
   }
 
  // Driver code
  let r, Area;
  r = 5;
 
  // Function calling
  Area = findArea(r);
 
  // displaying the area
  console.log("Area of Circle is: " + Area);
 
</script>


Output:

Area of Circle is: 78.53981633974483


Last Updated : 29 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads