📜  程序查找方形金字塔的表面积

📅  最后修改于: 2021-04-26 18:38:11             🧑  作者: Mango

给定方形金字塔的基本长度(b)和倾斜高度(s) 。任务是找到方形金字塔的表面积。具有方形底面,4个三角形面和一个顶点的金字塔是方形金字塔。

在这个图中
b-方形金字塔的基本长度。
s –方形金字塔的倾斜高度。
h-方形金字塔的高度。
例子:

Input: b = 3, s = 4
Output: 33

Input: b = 4, s = 5
Output: 56

用于计算表面的公式是具有(b)基础长度和(s)倾斜高度的方形金字塔。

    $$ surface\ area (A) = 2 \times b \times s + b^{2} $$

下面是使用上述公式的实现:

C++
// CPP program to find the surface area
// Of Square pyramid
#include 
using namespace std;
 
// function to find the surface area
int surfaceArea(int b, int s)
{
 
    return 2 * b * s + pow(b, 2);
}
 
// Driver program
int main()
{
    int b = 3, s = 4;
 
    // surface area of the square pyramid
    cout << surfaceArea(b, s) << endl;
    return 0;
}


Java
// Java program to find the surface area
// Of Square pyramid
 
import java.io.*;
 
class GFG {
 
 
// function to find the surface area
static int surfaceArea(int b, int s)
{
 
    return 2 * b * s + (int)Math.pow(b, 2);
}
 
// Driver program
 
 
    public static void main (String[] args) {
         
    int b = 3, s = 4;
 
    // surface area of the square pyramid
    System.out.println( surfaceArea(b, s));
    }
}
//This code is contributed by anuj_67..


Python 3
# Python 3 program to find the
# surface area Of Square pyramid
 
# function to find the surface area
def surfaceArea(b, s):
 
    return 2 * b * s + pow(b, 2)
 
# Driver Code
if __name__ == "__main__":
    b = 3
    s = 4
 
    # surface area of the square pyramid
    print(surfaceArea(b, s))
 
# This code is contributed
# by ChitraNayal


C#
// C# program to find the surface
// area Of Square pyramid
using System;
 
class GFG
{
 
// function to find the surface area
static int surfaceArea(int b, int s)
{
 
    return 2 * b * s + (int)Math.Pow(b, 2);
}
 
// Driver Code
public static void Main ()
{
    int b = 3, s = 4;
     
    // surface area of the square pyramid
    Console.WriteLine(surfaceArea(b, s));
}
}
 
// This code is contributed
// by inder_verma


PHP


Javascript


输出:
33