Horje
JavaScript Program to Find the Volume of Cylinder

We are going to see JavaScript Program to Find the Volume of Cylinder. We use direct formula to calculate volume of cylinder. A cylinder is a three-dimensional geometric shape that consists of two parallel circular bases connected by a curved surface.

Formula used

V = πr2h

where:

  • V is volume of cylinder
  • π is mathematical constant whose value is equal to 3.14
  • r is radius of cylinder
  • h is height of cylinder

Approach

We will create a function and pass radius and height as parameter. Calculate the volume of the cylinder using the formula. Return the calculated volume

Example: This example shows the finding the volume of cylinder using direct formula.

JavaScript
// program to calculate volume of cylinder

function VolumeOfCylinder(radius, height) {

    // volume of the cylinder 
    // using the formula V = πr^2h

    let volume = Math.PI *
     Math.pow(radius, 2) * height;
    return volume;
}

// Radius of the cylinder
let radius = 5;

// Height of the cylinder 
let height = 10;

let volume = VolumeOfCylinder(radius, height);
console.log("Volume of the cylinder is :", volume);

Output
Volume of the cylinder is : 785.3981633974483

Time Complexity: O(1)

Space Complexity: O(1)




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
Sum of the Series: 1 + 1/2 + 1/3 + ... + 1/n using JavaScript Sum of the Series: 1 + 1/2 + 1/3 + ... + 1/n using JavaScript
Find the Sum of the Series: 1/1! + 1/2! + 1/3! + ... + 1/n! using JavaScript ? Find the Sum of the Series: 1/1! + 1/2! + 1/3! + ... + 1/n! using JavaScript ?
Check if Two Numbers are Coprime using JavaScript Check if Two Numbers are Coprime using JavaScript
Find the Sum of the Series: 1 + 1/3 + 1/5 + ... + 1/(2n-1) using JavaScript ? Find the Sum of the Series: 1 + 1/3 + 1/5 + ... + 1/(2n-1) using JavaScript ?
JSON Interview Questions JSON Interview Questions

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13