find the surface area of a triangular prism in csharp

To find the surface area of a triangular prism, we need to find the areas of each face and then add them up.

Here's the code in C#:

main.cs
using System;

namespace SurfaceAreaTriangularPrism
{
    class Program
    {
        static void Main(string[] args)
        {
            // input dimensions
            double baseLength = 5;
            double height = 8;
            double width = 4;

            // calculate area of each face
            double baseArea = baseLength * height / 2;
            double sideArea = height * width;
            double endArea = baseLength * width;

            // calculate surface area
            double surfaceArea = 2 * baseArea + 2 * sideArea + 2 * endArea;

            Console.WriteLine("Surface Area of Triangular Prism: " + surfaceArea);
        }
    }
}
667 chars
26 lines

In the above code, we first input the dimensions of the triangular prism. We then calculate the area of each face using the appropriate formulae. Finally, we add all the areas together to get the surface area of the prism, which we display using Console.WriteLine().

gistlibby LogSnag