find the surface area of a triangular prism in swift

To find the surface area of a triangular prism, you need to calculate the areas of all its faces and add them up.

Here's the code to find the surface area of a triangular prism in Swift:

main.swift
func surfaceAreaOfTriangularPrism(base: Double, height: Double, length: Double) -> Double {
    let baseArea = base * height //area of the base (triangle)
    let sideArea = 3 * height * length //area of the three rectangular sides
    return baseArea + sideArea //total surface area
}
286 chars
6 lines

To use this function, simply call it and provide the values for the base, height and length of your triangular prism:

main.swift
let surfaceArea = surfaceAreaOfTriangularPrism(base: 5.0, height: 7.0, length: 10.0)
print("The surface area of the triangular prism is: \(surfaceArea)")
154 chars
3 lines

This will output:

main.swift
The surface area of the triangular prism is: 185.0
51 chars
2 lines

So, if the base of the triangular prism is 5 units, height is 7 units and length is 10 units, then the surface area of the prism is 185 square units.

gistlibby LogSnag