
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Volume, Perimeter and Surface Area of Cuboid in C#
What is a Cuboid?
A cuboid is a three-dimensional figure with six rectangular faces, where opposite faces are equal in dimensions. We can calculate the volume, perimeter, and surface area of a cuboid using specific formulas based on its length, breadth, and height.
Problem Statement
Given length, breadth, and height. You need to find its volume, perimeter, and surface area using different approaches in C#.
Formulas for Cuboid Calculations
The following are the formulas for the volume, perimeter, and surface area of a cuboid:
The Volume of a Cuboid:
Volume = length à breadth à height
The Perimeter of a Cuboid:
Perimeter = 4 Ã (length + breadth + height)
Surface Area of a Cuboid:
Surface Area = 2 à (length à breadth + breadth à height + height à length)
Where:
- Length: The horizontal side of the cuboid.
- Breadth: The width of the cuboid.
- Height: The vertical side of the cuboid.
Example 1
Input:
Length = 6 units
Breadth = 4 units
Height = 3 units
Output:
Volume of cuboid = 72 cubic units
Perimeter of cuboid = 52 units
Surface Area of cuboid = 108 square units
Explanation:
- Volume = 6 Ã 4 Ã 3 = 72
- Perimeter = 4 Ã (6 + 4 + 3) = 52
- Surface Area = 2 Ã (6 Ã 4 + 4 Ã 3 + 3 Ã 6) = 108
Example 2
Input:
Length = 8 units
Breadth = 5 units
Height = 4 units
Output:
Volume of cuboid = 160 cubic units
Perimeter of cuboid = 68 units
Surface Area of cuboid = 164 square units
Explanation:
- Volume = 8 Ã 5 Ã 4 = 160
- Perimeter = 4 Ã (8 + 5 + 4) = 68
- Surface Area = 2 Ã (8 Ã 5 + 5 Ã 4 + 4 Ã 8) = 164
Find Volume, Perimeter and Surface Area of Cuboid Using Formula
This is the simplest approach where we directly calculate values using formulas.
Steps for Implementation
- Define length, breadth, and height.
- Calculate each value using the formulas.
- Output the results.
Implementation Code
using System; class Program { static void Main() { double length = 6; double breadth = 4; double height = 3; double volume = length * breadth * height; double perimeter = 4 * (length + breadth + height); double surfaceArea = 2 * (length * breadth + breadth * height + height * length); Console.WriteLine($"Cuboid Dimensions: Length = {length}, Breadth = {breadth}, Height = {height}"); Console.WriteLine($"Volume: {volume} cubic units"); Console.WriteLine($"Perimeter: {perimeter} units"); Console.WriteLine($"Surface Area: {surfaceArea} square units"); } }
Output:
Cuboid Dimensions: Length = 6, Breadth = 4, Height = 3 Volume: 72 cubic units Perimeter: 52 units Surface Area: 108 square units
Find Volume, Perimeter and Surface Area of Cuboid Using Functions
We can also use functions to calculate volume, perimeter, and surface area for better code reusability.
Steps for Implementation
- Create separate functions for volume, perimeter, and surface area.
- Call these functions with the required dimensions as input.
- Output the results.
Implementation Code
using System; class Program { static double CalculateVolume(double length, double breadth, double height) { return length * breadth * height; } static double CalculatePerimeter(double length, double breadth, double height) { return 4 * (length + breadth + height); } static double CalculateSurfaceArea(double length, double breadth, double height) { return 2 * (length * breadth + breadth * height + height * length); } static void Main() { double length = 8; double breadth = 2; double height = 5; double volume = CalculateVolume(length, breadth, height); double perimeter = CalculatePerimeter(length, breadth, height); double surfaceArea = CalculateSurfaceArea(length, breadth, height); Console.WriteLine($"Cuboid Dimensions: Length = {length}, Breadth = {breadth}, Height = {height}"); Console.WriteLine($"Volume: {volume} cubic units"); Console.WriteLine($"Perimeter: {perimeter} units"); Console.WriteLine($"Surface Area: {surfaceArea} square units"); } }
Output:
Cuboid Dimensions: Length = 8, Breadth = 2, Height = 5 Volume: 80 cubic units Perimeter: 60 units Surface Area: 132 square units
Time Complexity: O(1)
Space Complexity: O(1)