find the surface area of a cone in typescript

To find the surface area of a cone, you can use the formula:

SA = πr² + πr√(r² + h²)

Where r is the radius of the base and h is the height of the cone.

Here's the implementation in TypeScript:

index.ts
function coneSurfaceArea(radius: number, height: number): number {
  const baseArea = Math.PI * Math.pow(radius, 2);
  const slantHeight = Math.sqrt(Math.pow(radius, 2) + Math.pow(height, 2));
  const lateralArea = Math.PI * radius * slantHeight;
  const surfaceArea = baseArea + lateralArea;
  return surfaceArea;
}
317 chars
8 lines

To use this function, simply call it with the radius and height of the cone:

index.ts
const radius = 5;
const height = 10;
const surfaceArea = coneSurfaceArea(radius, height);
console.log(surfaceArea); // Output: 235.61944901923448
146 chars
5 lines

In this example, the surface area of a cone with a radius of 5 and height of 10 is approximately 235.62 square units.

gistlibby LogSnag