📜  计算三角棱镜表面积的程序

📅  最后修改于: 2021-10-23 08:35:21             🧑  作者: Mango

在数学中,三棱柱是由相等的平行线连接两个相同端部的三维立体形状,有5个面、9条边和6个顶点。

其中“b”是底边的长度,“h”是三角形的高度,“s1, s2, s3”是三角形各边的长度,H是棱柱的高度(即也是矩形的长度)。
给定底、三角形的高、棱柱的高和三角形底边各边的长度,任务是计算三棱柱的表面积。
例子:

表面积计算公式:
如上所述,棱镜包含面积为(1/2)*(b)*(h) 的两个三角形和面积为H*s1、H*s2 和 H*s3 的三个矩形。
现在在添加所有项后,我们得到总表面积:

SA = b * h + (s1 + s2 + s3 ) * H
C++
// C++ Program to calculate the
// Surface area of a triangular prism
#include 
using namespace std;
 
// Function for calculating the area
void Calculate_area()
{
    // Initialization
    float b = 3, h = 4, s1 = 3, s2 = 6;
    float s3 = 6, Ht = 8, SA;
 
    // Formula for calculating the area
    SA = b * h + (s1 + s2 + s3) * Ht;
 
    // Displaying the area
    cout << "The area of triangular prism is : " << SA;
}
 
// Driver code
int main()
{
    // Function calling
    Calculate_area();
 
    return 0;
}


C
// C Program to calculate the
// Surface area of a triangular prism
#include 
 
// Function for calculating the area
void Calculate_area()
{
    // Initialization
    float b = 3, h = 4, s1 = 3, s2 = 6;
    float s3 = 6, Ht = 8, SA;
 
    // Formula for calculating the area
    SA = b * h + (s1 + s2 + s3) * Ht;
 
    // Displaying the output
    printf("The area of triangular prism is : %f", SA);
}
 
// Driver code
int main()
{
    // Function calling
    Calculate_area();
 
    return 0;
}


Java
// Java Program to calculate the
// Surface area of a triangular prism
 
import java.util.Scanner;
public class Prism {
 
    public static void Calculate_area()
    {
        // Initialization
        double b = 3, h = 4, s1 = 3, s2 = 6;
        double s3 = 6, Ht = 8, SA;
 
        // Formula for calculating the area
        SA = b * h + (s1 + s2 + s3) * Ht;
 
        // Displaying the area
        System.out.printf("The area of triangular prism is : %f", SA);
    }
    public static void main(String[] args)
    {
        Calculate_area();
    }
}
// This code is contributed by Nishant Tanwar


Python3
# Python3 Program to calculate the
# Surface area of a triangular prism
 
# Function for calculating the area
def Calculate_area():
     
    # Initialization
    b = 3
    h = 4
    s1 = 3
    s2 = 6
    s3 = 6
    Ht = 8
 
    # Formula for calculating the area
    SA = b * h + (s1 + s2 + s3) * Ht
 
    # Displaying the area
    print ("The area of triangular prism is :",SA)
 
# Driver code
if __name__ == '__main__':
    # Function calling
    Calculate_area()
 
# This code is contributed by
# Surendra_Gangwar


C#
// C# Program to calculate the
// Surface area of a triangular prism
using System;
public class Prism {
  
    static void Calculate_area()
    {
        // Initialization
        double b = 3, h = 4, s1 = 3, s2 = 6;
        double s3 = 6, Ht = 8, SA;
  
        // Formula for calculating the area
        SA = b * h + (s1 + s2 + s3) * Ht;
  
        // Displaying the area
        Console.WriteLine("The area of triangular prism is : " + SA);
    }
    static public void Main(String[] args)
    {
        Calculate_area();
    }
}


PHP


Javascript


输出
The area of triangular prism is : 132