给定八边形棱镜的基本长度,高度和距离,我们必须找到给定参数的八角形棱镜的表面积和体积。八边形棱柱是一个立体三维物体,共有10个面,24个边和16个顶点。两端的两个面均为八边形,其余面为矩形。
其中a是基本长度, h是高度, d是八边形棱镜的距离。
Area = 2 * base * distance
Surface area = (2 * Area) + ( 8 * base * height )
Volume = ( Area * height )
例子:
Input: h = 2, a = 4, d = 3
Output:
Surface Area : 112
Volume : 48
Input: h = 1, a = 6, d = 2
Output:
Surface Area : 96
Volume : 24
C++
// C++ program to find the
// Surface area and volume
// of octagonal prism
#include
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
输出:
Surface area: 96
Volume: 24