Program to find the surface area of the square pyramid - GeeksforGeeks

22 Mar, 2021
Given the base length(b) and slant height(s) of the square pyramid. The task is to find the surface area of the Square Pyramid. A Pyramid with a square base, 4 triangular faces, and an apex is a square pyramid. 
In this figure, b – base length of the square pyramid. s – slant height of the square pyramid. h – height of the square pyramid.Examples:  
Input: b = 3, s = 4
Output: 33

Input: b = 4, s = 5
Output: 56
 
Formula for calculating the surface are of the square pyramid with (b) base length and (s) slant height. 
    
Below is the implementation using the above formula:  
C++
Java
Python 3
C#
PHP
Javascript
// CPP program to find the surface area// Of Square pyramid#include <bits/stdc++.h>using namespace std; // function to find the surface areaint surfaceArea(int b, int s){     return 2 * b * s + pow(b, 2);} // Driver programint main(){    int b = 3, s = 4;     // surface area of the square pyramid    cout << surfaceArea(b, s) << endl;    return 0;}
// Java program to find the surface area// Of Square pyramid import java.io.*; class GFG {  // function to find the surface areastatic 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 program to find the# surface area Of Square pyramid # function to find the surface areadef surfaceArea(b, s):     return 2 * b * s + pow(b, 2) # Driver Codeif __name__ == "__main__":    b = 3    s = 4     # surface area of the square pyramid    print(surfaceArea(b, s)) # This code is contributed# by ChitraNayal
// C# program to find the surface// area Of Square pyramidusing System; class GFG{ // function to find the surface areastatic int surfaceArea(int b, int s){     return 2 * b * s + (int)Math.Pow(b, 2);} // Driver Codepublic 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// PHP program to find the surface// area Of Square pyramid // function to find the surface areafunction surfaceArea($b, $s){    return 2 * $b * $s + pow($b, 2);} // Driver Code$b = 3; $s = 4; // surface area of the// square pyramidecho surfaceArea($b, $s); // This code is contributed// by anuj_67?>
<script>// javascript program to find the surface area// Of Square pyramid // function to find the surface areafunction surfaceArea(b , s){    return 2 * b * s + parseInt(Math.pow(b, 2));} // Driver programvar b = 3, s = 4; // surface area of the square pyramiddocument.write( surfaceArea(b, s)); // This code is contributed by shikhasingrajput</script>
33
 
vt_m
inderDuMCA
ukasp
shikhasingrajput
area-volume-programs
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program for distance between two points on earth
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
Convex Hull | Set 2 (Graham Scan)
Given n line segments, find if any two segments intersect
Closest Pair of Points | O(nlogn) Implementation
Program for Fibonacci numbers
Write a program to print all permutations of a given string
C++ Data Types
Set in C++ Standard Template Library (STL)
Coin Change | DP-7