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++
#include <bits/stdc++.h>
using namespace std;
double surface_area_octahedron( double side)
{
return (2*( sqrt (3))*(side*side));
}
int main()
{
double side = 7;
cout << "Surface area of octahedron ="
<< surface_area_octahedron(side)
<< endl;
}
|
Java
import java.io.*;
import java.util.*;
class GFG {
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));
}
}
|
Python3
import math
def surface_area_octahedron( side):
return ( 2 * (math.sqrt( 3 )) * (side * side))
side = 7
print ( "Surface area of octahedron =" ,
surface_area_octahedron(side))
|
C#
using System;
class GFG {
static double surface_area_octahedron( double side)
{
return (2 * (Math.Sqrt(3)) * (side * side));
}
public static void Main()
{
double side = 7;
Console.WriteLine( "Surface area of octahedron ="
+ surface_area_octahedron(side));
}
}
|
PHP
<?php
function surface_area_octahedron( $side )
{
return (2 * (sqrt(3)) *
( $side * $side ));
}
$side = 7;
echo ( "Surface area of octahedron =" );
echo ( surface_area_octahedron( $side ));
?>
|
Javascript
<script>
function surface_area_octahedron(side)
{
return (2 * (Math.sqrt(3)) * (side*side));
}
let side = 7;
document.write( "Surface area of octahedron =" +
surface_area_octahedron(side));
</script>
|
Output:
Surface area of octahedron =169.741
Time complexity : O(1)
Auxiliary Space : O(1)
Last Updated :
20 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...