给定四棱锥的底长(b)和斜高(s) 。任务是找到方形金字塔的表面积。具有方形底部、4 个三角形面和一个顶点的金字塔是方形金字塔。
在这个图中,
b -的正方棱锥的碱基长度。
的S -方形金字塔的倾斜高度。
h——四棱锥的高度。
例子:
Input: b = 3, s = 4
Output: 33
Input: b = 4, s = 5
Output: 56
计算表面的公式是具有(b)底长和(s)斜高的四方锥体。
下面是使用上述公式的实现:
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
如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程和学生竞争性编程现场课程。