JavaScript Program to Find Curved Surface Area of a Cone
A cone is a three-dimensional geometric shape. It consists of a base having the shape of a circle and a curved side (the lateral surface) ending up in a tip called the apex or vertex. We will be going to learn how can we calculate it by using JavaScript.
Formula used:
Curved Surface area of a Cone = πrl
Examples:
Input: radius = 0.8, slant height = 20
Output: Curved Surface Area = 50.26548245743669
Input: radius = 0.2, slant height = 5
Output: Curved Surface Area = 3.141592653589793
Approach
- A function named CurvedSurfaceAreaofCone is defined, which takes the radius and slant height as two parameters.
- The function proceeds to calculate the Curved Surface Area of the Cone using the formula (Π * r * l). Where ‘r’ is the radius of the base2. ‘l’ is the slant height of the cone.
- The calculated Curved Surface Area is returned as the result of the function.
Example: Below is the function to find the Curved Surface Area of the Cone:
// Javascript program to find
// Curved Surface area of Cone
function CurvedSurfaceAreaofCone(r, l) {
return (Math.PI * r * l);
}
let r = 0.8;
let l = 20;
let output = CurvedSurfaceAreaofCone(r, l);
console.log(output)
Output
50.26548245743669
Time complexity: O(1), as the execution time is constant and does not grow with the size of the input.
Auxiliary Space complexity: O(1) as it uses a constant amount of memory regardless of the input size.
Contact Us