Programa para hallar Área Superficial y Volumen de Prisma Octogonal

Dada la longitud de la base, la altura y la distancia del prisma octogonal, tenemos que encontrar el área de superficie y el volumen del prisma octogonal para los parámetros dados. El prisma octogonal es un objeto tridimensional sólido que tiene un total de 10 caras, 24 aristas y 16 vértices. Las dos caras en cada extremo son octágonos y el resto de las caras son rectangulares.
 

donde a es la longitud de la base, h es la altura y d es la distancia del prisma octogonal. 
 

Área = 2 * base * distancia 
Área de superficie = (2 * Área) + (8 * base * altura) 
Volumen = (Área * altura)

Ejemplos:
 

Entrada: h = 2, a = 4, d = 3 
Salida: 
Área de superficie: 112 
Volumen: 48
Entrada: h = 1, a = 6, d = 2 
Salida: 
Área de superficie: 96 
Volumen: 24 
 

C++

// C++ program to find the
// Surface area and volume
// of octagonal prism
#include <iostream>
using namespace std;
 
// Function to find the
// Volume of octagonal prism
void find_volume(float area, float h)
{
    // Formula to calculate
    // volume = (area * h)
    float Volume = (area * h);
     
    // Display volume
    cout << "Volume: "
         << Volume << endl;
}
     
// Function to find the
// surface area of octagonal prism
void find_Surface_area(float area,
                       float a, float h)
{
         
    // Formula to calculate Surface area
    float Surface_area = (2 * area) +
                         (8 * a * h);
     
    cout << "Surface area: "
         << Surface_area << endl;
}
 
// Driver Code
int main()
{
    float h = 1;
    float a = 6;
    float d = 2;
    float area = 2 * a * d;
     
    find_Surface_area(area, a, h);
     
    find_volume(area, h);
     
    return 0;
}
 
// This code is contributed by AnkitRai01

Java

// Java program to find the
// Surface area and volume
// of octagonal prism
public class GFG {
 
    // Function to find the
    // Volume of octagonal prism
    static void find_volume(double area,double h){
         
        // Formula to calculate
        // volume = (area * h)
        double Volume = (area * h) ;
         
        // Display volume
        System.out.println("Volume: " + Volume);
    }
     
    // Function to find the
    // surface area of octagonal prism
    static void find_Surface_area(double area, double a, double h){
         
        // Formula to calculate Surface area
        double Surface_area = (2 * area)+(8 * a * h) ;
         
        System.out.println("Surface area: " + Surface_area) ;
    }
 
    // Driver Code
    public static void main (String[] args)
    {
        double h = 1 ;
        double a = 6 ;
        double d = 2 ;
        double area = 2 * a * d ;
         
         
        find_Surface_area(area, a, h) ;
         
        find_volume(area, h) ;
     
    }
}
 
// This code is contributed by AnkitRai01

Python3

# Python3 program to find the
# Surface area and volume
# of octagonal prism
import math
     
 
# Function to find the
# Volume of octagonal prism
def find_volume(area, h):
     
    # Formula to calculate
    # volume = (area * h)
    Volume = (area * h)
     
    # Display volume
    print("Volume: ", end =" ")
    print(Volume)
 
# Function to find the
# surface area of octagonal prism
def find_Surface_area(area, a, h):
     
    # Formula to calculate Surface area
    Surface_area = (2 * area)+(8 * a * h)
     
    print("Surface area: ", end =" ")
    print(Surface_area)
     
# Driver Code
h = 1
a = 6
d = 2
area = 2 * a * d
 
 
find_Surface_area(area, a, h)
 
find_volume(area, h)

C#

// C# program to find the surface area
// and volume of octagonal prism
using System;
 
class GFG {
 
// Function to find the volume
// of octagonal prism
static void find_volume(double area, double h)
{
         
    // Formula to calculate
    // volume = (area * h)
    double Volume = (area * h);
         
    // Display volume
    Console.WriteLine("Volume: " + Volume);
}
     
// Function to find the surface 
// area of octagonal prism
static void find_Surface_area(double area, double a,
                                           double h)
{
         
    // Formula to calculate surface area
    double Surface_area = (2 * area) + (8 * a * h);
     
    Console.WriteLine("Surface area: " + Surface_area);
}
 
// Driver Code
public static void Main (string[] args)
{
    double h = 1;
    double a = 6;
    double d = 2;
    double area = 2 * a * d;
     
    find_Surface_area(area, a, h);
    find_volume(area, h);
}
}
 
// This code is contributed by AnkitRai01

Javascript

<script>
// javascript program to find the
// Surface area and volume
// of octagonal prism
 
// Function to find the
// Volume of octagonal prism
function find_volume( area,  h)
{
 
    // Formula to calculate
    // volume = (area * h)
    let Volume = (area * h);
     
    // Display volume
    document.write( "Volume: "
         + Volume +"<br/>");
}
     
// Function to find the
// surface area of octagonal prism
function find_Surface_area( area,
                        a,  h)
{
         
    // Formula to calculate Surface area
    let Surface_area = (2 * area) +
                         (8 * a * h);
     
    document.write("Surface area: "
         +Surface_area  +"<br/>");
}
 
// Driver Code
    let h = 1;
    let a = 6;
    let d = 2;
    let area = 2 * a * d;
    find_Surface_area(area, a, h);
    find_volume(area, h);
     
// This code is contributed by todaysgaurav
 
</script>
Producción: 

Surface area:  96
Volume:  24

 

Complejidad de tiempo : O (1) porque realiza operaciones constantes

Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por virusbuddha 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 *