Find the volume of hexagonal prism
Here given code implementation process.
//C Program
//Find the volume of hexagonal prism
#include <stdio.h>
#include <math.h>
//Calculate volume of hexagonal prism by given base and height
void hexagonal_volume(double base, double height)
{
// Formula
// Here a is base and h is height
// (3√3)
// ----- a²h
// 2
double volume = 3 * (sqrt(3)) * base * base * height / 2;
//Display result
printf(" Hexagonal Prism Size [ base : %lf, height : %lf] ", base, height);
printf("\n Volume : %lf\n\n", volume);
}
int main()
{
//Test Case
hexagonal_volume(4, 8);
hexagonal_volume(5, 5);
hexagonal_volume(6, 5.8);
return 0;
}
Output
Hexagonal Prism Size [ base : 4.000000, height : 8.000000]
Volume : 332.553755
Hexagonal Prism Size [ base : 5.000000, height : 5.000000]
Volume : 324.759526
Hexagonal Prism Size [ base : 6.000000, height : 5.800000]
Volume : 542.478313
// Java Program
// Find the volume of hexagonal prism
class Hexagonal
{
//Calculate volume of hexagonal prism by given base and height
public void hexagonal_volume(double base, double height)
{
// Formula
// Here a is base and h is height
// (3√3)
// ----- a²h
// 2
double volume = 3 * (Math.sqrt(3)) * base * base * height / 2;
//Display result
System.out.print(" Hexagonal Prism Size [ base : " + base + ", height : " + height + "] ");
System.out.print("\n Volume : " + volume + "\n\n");
}
public static void main(String[] args)
{
Hexagonal obj = new Hexagonal();
//Test Cases
obj.hexagonal_volume(4, 8);
obj.hexagonal_volume(5, 5);
obj.hexagonal_volume(6, 5.8);
}
}
Output
Hexagonal Prism Size [ base : 4.0, height : 8.0]
Volume : 332.55375505322445
Hexagonal Prism Size [ base : 5.0, height : 5.0]
Volume : 324.7595264191645
Hexagonal Prism Size [ base : 6.0, height : 5.8]
Volume : 542.4783129305723
// C++ Program
// Find the volume of hexagonal prism
#include<iostream>
#include <math.h>
using namespace std;
class Hexagonal
{
public:
//Calculate volume of hexagonal prism by given base and height
void hexagonal_volume(double base, double height)
{
// Formula
// Here a is base and h is height
// (3√3)
// ----- a²h
// 2
double volume = 3 *(sqrt(3)) *base *base *height / 2;
cout << " Hexagonal Prism Size [ base : " << base << ", height : " << height << "] ";
cout << "\n Volume : " << volume << "\n\n";
}
};
int main()
{
Hexagonal obj = Hexagonal();
//Test Cases
obj.hexagonal_volume(4, 8);
obj.hexagonal_volume(5, 5);
obj.hexagonal_volume(6, 5.8);
return 0;
}
Output
Hexagonal Prism Size [ base : 4, height : 8]
Volume : 332.554
Hexagonal Prism Size [ base : 5, height : 5]
Volume : 324.76
Hexagonal Prism Size [ base : 6, height : 5.8]
Volume : 542.478
// C# Program
// Find the volume of hexagonal prism
using System;
class Hexagonal
{
//Calculate volume of hexagonal prism by given base and height
public void hexagonal_volume(double base_side, double height)
{
// Formula
// Here a is base and h is height
// (3√3)
// ----- a²h
// 2
double volume = 3 * (Math.Sqrt(3)) * base_side * base_side * height / 2;
Console.Write(" Hexagonal Prism Size [ base : " + base_side + ", height : " + height + "] ");
Console.Write("\n Volume : " + volume + "\n\n");
}
public static void Main(String[] args)
{
Hexagonal obj = new Hexagonal();
//Test Cases
obj.hexagonal_volume(4, 8);
obj.hexagonal_volume(5, 5);
obj.hexagonal_volume(6, 5.8);
}
}
Output
Hexagonal Prism Size [ base : 4, height : 8]
Volume : 332.553755053224
Hexagonal Prism Size [ base : 5, height : 5]
Volume : 324.759526419165
Hexagonal Prism Size [ base : 6, height : 5.8]
Volume : 542.478312930572
<?php
// Php Program
// Find the volume of hexagonal prism
class Hexagonal
{
//Calculate volume of hexagonal prism by given base and height
public function hexagonal_volume($base, $height)
{
// Formula
// Here a is base and h is height
// (3√3)
// ----- a²h
// 2
$volume = 3 *(sqrt(3)) *$base *$base *$height / 2;
//Display result
echo(" Hexagonal Prism Size [ base : ". $base .", height : ". $height ."] ");
echo("\n Volume : ". $volume ."\n\n");
}
}
function main()
{
$obj = new Hexagonal();
//Test Cases
$obj->hexagonal_volume(4, 8);
$obj->hexagonal_volume(5, 5);
$obj->hexagonal_volume(6, 5.8);
}
main();
Output
Hexagonal Prism Size [ base : 4, height : 8]
Volume : 332.55375505322
Hexagonal Prism Size [ base : 5, height : 5]
Volume : 324.75952641916
Hexagonal Prism Size [ base : 6, height : 5.8]
Volume : 542.47831293057
// Node Js Program
// Find the volume of hexagonal prism
class Hexagonal
{
//Calculate volume of hexagonal prism by given base and height
hexagonal_volume(base, height)
{
// Formula
// Here a is base and h is height
// (3√3)
// ----- a²h
// 2
var volume = 3 *(Math.sqrt(3)) *base *base *height / 2;
//Display result
process.stdout.write(" Hexagonal Prism Size [ base : " + base + ", height : " + height + "] ");
process.stdout.write("\n Volume : " + volume + "\n\n");
}
}
function main(args)
{
var obj = new Hexagonal();
//Test Cases
obj.hexagonal_volume(4, 8);
obj.hexagonal_volume(5, 5);
obj.hexagonal_volume(6, 5.8);
}
main();
Output
Hexagonal Prism Size [ base : 4, height : 8]
Volume : 332.55375505322445
Hexagonal Prism Size [ base : 5, height : 5]
Volume : 324.7595264191645
Hexagonal Prism Size [ base : 6, height : 5.8]
Volume : 542.4783129305723
# Python 3 Program
# Find the volume of hexagonal prism
import math
class Hexagonal :
# Calculate volume of hexagonal prism by given base and height
def hexagonal_volume(self, base, height) :
# Formula
# Here a is base and h is height
# (3√3)
# ----- a²h
# 2
volume = 3 * (math.sqrt(3)) * base * base * height / 2
# Display result
print(" Hexagonal Prism Size [ base : ", base ,", height : ", height ,"] ", end = "")
print("\n Volume : ", volume ,"\n\n", end = "")
def main() :
obj = Hexagonal()
# Test Cases
obj.hexagonal_volume(4, 8)
obj.hexagonal_volume(5, 5)
obj.hexagonal_volume(6, 5.8)
if __name__ == "__main__": main()
Output
Hexagonal Prism Size [ base : 4 , height : 8 ]
Volume : 332.55375505322445
Hexagonal Prism Size [ base : 5 , height : 5 ]
Volume : 324.7595264191645
Hexagonal Prism Size [ base : 6 , height : 5.8 ]
Volume : 542.4783129305723
# Ruby Program
# Find the volume of hexagonal prism
class Hexagonal
# Calculate volume of hexagonal prism by given base and height
def hexagonal_volume(base, height)
# Formula
# Here a is base and h is height
# (3√3)
# ----- a²h
# 2
volume = 3 * (Math.sqrt(3)) * base * base * height / 2
# Display result
print(" Hexagonal Prism Size [ base : ", base ,", height : ", height ,"] ")
print("\n Volume : ", volume ,"\n\n")
end
end
def main()
obj = Hexagonal.new()
# Test Cases
obj.hexagonal_volume(4, 8)
obj.hexagonal_volume(5, 5)
obj.hexagonal_volume(6, 5.8)
end
main()
Output
Hexagonal Prism Size [ base : 4, height : 8]
Volume : 332.55375505322445
Hexagonal Prism Size [ base : 5, height : 5]
Volume : 324.7595264191645
Hexagonal Prism Size [ base : 6, height : 5.8]
Volume : 542.4783129305723
// Scala Program
// Find the volume of hexagonal prism
class Hexagonal
{
//Calculate volume of hexagonal prism by given base and height
def hexagonal_volume(base: Double, height: Double): Unit = {
// Formula
// Here a is base and h is height
// (3√3)
// ----- a²h
// 2
var volume: Double = 3 * (Math.sqrt(3)) * base * base * height / 2;
//Display result
print(" Hexagonal Prism Size [ base : " + base + ", height : " + height + " ] ");
print("\n Volume : " + volume + "\n\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: Hexagonal = new Hexagonal();
//Test Cases
obj.hexagonal_volume(4, 8);
obj.hexagonal_volume(5, 5);
obj.hexagonal_volume(6, 5.8);
}
}
Output
Hexagonal Prism Size [ base : 4.0, height : 8.0 ]
Volume : 332.55375505322445
Hexagonal Prism Size [ base : 5.0, height : 5.0 ]
Volume : 324.7595264191645
Hexagonal Prism Size [ base : 6.0, height : 5.8 ]
Volume : 542.4783129305723
// Swift Program
// Find the volume of hexagonal prism
import Foundation
class Hexagonal
{
//Calculate volume of hexagonal prism by given base and height
func hexagonal_volume(_ base: Double, _ height: Double)
{
// Formula
// Here a is base and h is height
// (3√3)
// ----- a²h
// 2
let volume: Double = 3 * (sqrt(3)) * base * base * height / 2;
//Display result
print(" Hexagonal Prism Size [ base : ", base ,", height : ", height ,"] ", terminator: "");
print("\n Volume : ", volume ,"\n\n", terminator: "");
}
}
func main()
{
let obj: Hexagonal = Hexagonal();
//Test Cases
obj.hexagonal_volume(4, 8);
obj.hexagonal_volume(5, 5);
obj.hexagonal_volume(6, 5.8);
}
main();
Output
Hexagonal Prism Size [ base : 4.0 , height : 8.0 ]
Volume : 332.553755053224
Hexagonal Prism Size [ base : 5.0 , height : 5.0 ]
Volume : 324.759526419165
Hexagonal Prism Size [ base : 6.0 , height : 5.8 ]
Volume : 542.478312930572
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment