Sunday, January 12, 2025
Google search engine
HomeData Modelling & AIProgram for Surface Area of Octahedron

Program for Surface Area of Octahedron

Given the sides of Octahedron then calculate the surface area.

Examples: 

Input  : 7
Output : 169.741

Input  : 9
Output : 280.59

An regular octahedron has eight faces, which are all in the shape of equilateral triangles.The area of an octahedron is 2 multiplied by the length of an edge squared multiplied by the square root of three.  

Formula: 
Surface area= 2*(sqrt(3))*(side*side)

C++




// CPP Program to calculate 
// surface area of Octahedron
#include <bits/stdc++.h>
using namespace std;
  
// utility Function
double surface_area_octahedron(double side)
{
    return (2*(sqrt(3))*(side*side));
}
  
// Driver Function
int main()
{
    double side = 7;
    cout << "Surface area of octahedron ="
        << surface_area_octahedron(side)
        << endl;
}


Java




// Java Program to calculate 
// surface area of Octahedron.
  
import java.io.*;
import java.util.*;
  
class GFG {
      
// utility Function
static double surface_area_octahedron(double side)
{
    return (2*(Math.sqrt(3))*(side*side));
}
    public static void main (String[] args) {
    double side = 7;
    System.out.println("Surface area of octahedron ="
                    + surface_area_octahedron(side)); 
      
    }
}
  
// This code is contributed by Gitanjali.


Python3




# Python Program to calculate 
# surface area of Octahedron.
import math
  
# utility Function
def surface_area_octahedron( side):
  
    return (2*(math.sqrt(3))*(side*side))
  
# driver code 
side = 7
print("Surface area of octahedron =" ,
      surface_area_octahedron(side))
  
# This code is contributed by Gitanjali.


C#




// C# program to calculate
// surface area of Octahedron.
using System;
  
class GFG {
  
    // utility Function
    static double surface_area_octahedron(double side)
    {
        return (2 * (Math.Sqrt(3)) * (side * side));
    }
      
    // Driver code
    public static void Main()
    {
        double side = 7;
        Console.WriteLine("Surface area of octahedron ="
                        + surface_area_octahedron(side));
    }
}
  
// This code is contributed by vt_m.


PHP




<?php
// PHP Program to calculate 
// surface area of Octahedron
  
// utility Function
function surface_area_octahedron($side)
{
    return (2 * (sqrt(3)) * 
           ($side * $side));
}
  
// Driver Code
$side = 7;
echo("Surface area of octahedron =");
echo( surface_area_octahedron($side));
  
// This code is contributed by vt_m.
?>


Javascript




<script>
  
// JavaScript program to calculate 
// surface area of Octahedron.
  
// Utility Function
function surface_area_octahedron(side)
{
    return (2 * (Math.sqrt(3)) * (side*side));
}
  
// Driver Code
let side = 7;
  
document.write("Surface area of octahedron ="
               surface_area_octahedron(side)); 
  
// This code is contributed by avijitmondal1998
  
</script>


Output: 

Surface area of octahedron =169.741

Time complexity : O(1) 
Auxiliary Space : O(1)

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Recent Comments