Área de superficie y volumen del prisma hexagonal

Dada la arista de la base y la altura del prisma hexagonal, la tarea es encontrar el área de la superficie y el volumen del prisma hexagonal. En matemáticas, un prisma hexagonal es una forma sólida tridimensional que tiene 8 caras, 18 aristas y 12 vértices. Las dos caras en cada extremo son hexágonos y el resto de las caras del prisma hexagonal son rectangulares. 
 

hexagonal prism

donde a es la longitud de la base y h es la altura del prisma hexagonal.
 

Área de superficie =  6ah + 3\sqrt{3}a^{2}
Volumen = \frac{3\sqrt{3}}{2}a^{2}h
 

Ejemplos: 
 

Input : a = 4, h = 3
Output : Surface Area: 155.138443
         Volume: 124.707657

Input : a = 5, h = 10
Output : Surface Area: 429.904
         Volume: 649.519

C++

// C++ program to find the Surface Area
// and Volume of Hexagonal Prism.
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to calculate Surface area
void findSurfaceArea(float a, float h)
{
    float Area;
 
    // Formula to calculate surface area
    Area = 6 * a * h + 3 * sqrt(3) * a * a;
 
    // Display surface area
    cout << "Surface Area: " << Area;
    cout << "\n";
}
 
// Function to calculate Volume
void findVolume(float a, float h)
{
    float Volume;
 
    // formula to calculate Volume
    Volume = 3 * sqrt(3) * a * a * h / 2;
 
    // Display Volume
    cout << "Volume: " << Volume;
}
 
// Driver Code
int main()
{
    float a = 5, h = 10;
     
    // surface area function call
    findSurfaceArea(a, h);
 
    // volume function call
    findVolume(a, h);
 
    return 0;
}

Java

// Java program to find the Surface Area
// and Volume of Hexagonal Prism.
 
import java.io.*;
 
class GFG {
        
    // Function to calculate Surface area
    static void findSurfaceArea(float a, float h)
    {
        float Area;
 
        // Formula to calculate surface area
        Area = 6 * a * h + 3 * (float)(Math.sqrt(3)) * a * a;
     
        // Display surface area
        System.out.println("Surface Area: " + Area);
    }
     
    // Function to calculate Volume
    static void findVolume(float a, float h)
    {
        float Volume;
     
        // formula to calculate Volume
        Volume = 3 * (float)(Math.sqrt(3)) * a * a * h / 2;
     
        // Display Volume
        System.out.println("Volume: " + Volume);
    }
 
    // Driver code
    public static void main (String[] args)
    {
        float a = 5, h = 10;
     
        // surface area function call
        findSurfaceArea(a, h);
     
        // volume function call
        findVolume(a, h);
    }
}

Python3

# Python3 program to find the
# Surface Area and Volume
# of Hexagonal Prism.
import math
 
# Function to calculate
# Surface area
def findSurfaceArea(a, h):
    Area = 0;
 
    # Formula to calculate
    # surface area
    Area = (6 * a * h +
            3 * math.sqrt(3) * a * a);
 
    # Display surface area
    print("Surface Area:",
          round(Area, 3));
     
# Function to
# calculate Volume
def findVolume(a, h):
    Volume = 0;
 
    # formula to
    # calculate Volume
    Volume = (3 * math.sqrt(3) *
                a * a * h / 2);
 
    # Display Volume
    print("Volume:",
           round(Volume, 3));
 
# Driver Code
a = 5;
h = 10;
 
# surface area
# function call
findSurfaceArea(a, h);
 
# volume function call
findVolume(a, h);
 
# This code is contributed
# by mits

C#

// C# program to find the
// Surface Area and Volume
// of Hexagonal Prism.
using System;
 
class GFG
{
         
    // Function to calculate
    // Surface area
    static void findSurfaceArea(float a,
                                float h)
    {
        float Area;
 
        // Formula to calculate
        // surface area
        Area = 6 * a * h + 3 *
               (float)(Math.Sqrt(3)) * a * a;
     
        // Display surface area
        Console.WriteLine("Surface Area: " +
                                      Area);
    }
     
    // Function to
    // calculate Volume
    static void findVolume(float a,
                           float h)
    {
        float Volume;
     
        // formula to calculate Volume
        Volume = 3 * (float)(Math.Sqrt(3)) *
                              a * a * h / 2;
     
        // Display Volume
        Console.WriteLine("Volume: " +
                              Volume);
    }
 
    // Driver code
    public static void Main ()
    {
        float a = 5, h = 10;
     
        // surface area
        // function call
        findSurfaceArea(a, h);
     
        // volume function call
        findVolume(a, h);
    }
}
 
// This code is contributed
// by anuj_67.

PHP

<?php
// PHP program to find the
// Surface Area and Volume
// of Hexagonal Prism.
 
// Function to calculate
// Surface area
function findSurfaceArea($a, $h)
{
    $Area;
 
    // Formula to calculate
    // surface area
    $Area = 6 * $a * $h + 3 *
            sqrt(3) * $a * $a;
 
    // Display surface area
    echo "Surface Area: " ,
                $Area,"\n";
     
}
 
// Function to
// calculate Volume
function findVolume($a, $h)
{
    $Volume;
 
    // formula to
    // calculate Volume
    $Volume = 3 * sqrt(3) *
              $a * $a * $h / 2;
 
    // Display Volume
    echo "Volume: " , $Volume;
}
 
// Driver Code
$a = 5; $h = 10;
 
// surface area
// function call
findSurfaceArea($a, $h);
 
// volume function call
findVolume($a, $h);
 
// This code is contributed
// by anuj_67.
?>

Javascript

<script>
// javascript program to find the Surface Area
// and Volume of Hexagonal Prism.
 
// Function to calculate Surface area
function findSurfaceArea( a,  h)
{
    let Area;
 
    // Formula to calculate surface area
    Area = 6 * a * h + 3 * Math.sqrt(3) * a * a;
 
    // Display surface area
    document.write( "Surface Area: " + Area.toFixed(3) + "<br/>");
}
 
// Function to calculate Volume
function findVolume( a,  h)
{
    let Volume;
 
    // formula to calculate Volume
    Volume = 3 * Math.sqrt(3) * a * a * h / 2;
 
    // Display Volume
    document.write( "Volume: " + Volume.toFixed(3));
}
 
// Driver Code
    let a = 5, h = 10;
     
    // surface area function call
    findSurfaceArea(a, h);
 
    // volume function call
    findVolume(a, h);
     
// This code is contributed by todaysgaurav
 
</script>

Complejidad de tiempo : O(logn) 
Espacio auxiliar : O(1)

Publicación traducida automáticamente

Artículo escrito por Kanishk_Verma y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *