Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Surface Area and Volume of Hexagonal Prism in C programming
The surface area of any figure is the total area that its surface covers. A hexagonal prism is a three-dimensional figure that has a hexagon at both its ends.
In mathematics, a hexagonal prism is defined as a three-dimensional figure with 8 faces, 18 edges, and 12 vertices. It consists of two hexagonal bases connected by rectangular faces.
Syntax
Surface Area = 6ah + 3?3a² Volume = (3?3/2)a²h
Where:
- a = side length of the hexagonal base
- h = height of the prism
Example
The following program calculates both surface area and volume of a hexagonal prism −
#include <stdio.h>
#include <math.h>
int main() {
float a = 5.0, h = 10.0;
// Calculate surface area of hexagonal prism
float surface_area = 6 * a * h + 3 * sqrt(3) * a * a;
printf("Surface Area: %.2f<br>", surface_area);
// Calculate volume of hexagonal prism
float volume = 3 * sqrt(3) * a * a * h / 2;
printf("Volume: %.2f<br>", volume);
return 0;
}
Surface Area: 429.90 Volume: 649.52
How It Works
- Surface Area: Consists of 6 rectangular faces (6ah) plus 2 hexagonal bases (2 × 3?3a²/2 = 3?3a²)
- Volume: Base area (3?3a²/2) multiplied by height (h)
- The
sqrt(3)function calculates the square root of 3, which is approximately 1.732
Conclusion
This program demonstrates how to calculate the surface area and volume of a hexagonal prism using mathematical formulas. The surface area includes both the hexagonal bases and rectangular lateral faces, while the volume is the product of the base area and height.
Advertisements
