In this tutorial you will learn about the C Program to Find Volume and Surface Area of a Cuboid and its application with practical example.
C Program to Find Volume and Surface Area of a Cuboid
In this tutorial, we will learn to create a C program that will Find the Volume and Surface Area of a Cuboid in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Mathematical operations in C programming.
What is a cuboid?
The cuboid is a box-like geometrical structure used for storing items. The cuboid consists of 3 types of measurements in its structure.
- Height
- Width
- Length
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input heoght, length and width of the cuboid from the user. 3. <strong>C</strong><strong>alculating the Surface Area of a Cuboid </strong>using the code. 4. Printing the area of the <strong>Cuboid.</strong> 5. End the program. |
Program description:-
In today’s tutorial, we will create a program, that will calculate the Volume and Surface Area of a Cuboid using C programming. First, take the length, width and the height of the Cuboid as input from the user. Then we will find the surface area and the volume of a Cuboid using the mathematical functions and calculations. At last, we will print the Volume and Surface Area of a Cuboid.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/* C Program to find volume and Surface Area of a Cuboid */ #include <stdio.h>//including the header files of the program. int main() { //declaring the required variables for the program. float l, w, h; float SA, vol, LSA; //l = it will hold the input length from the user. //h = it will hold the input height from the user. //w = it will hold the input width from the user. //vol it will hold the volume of the cuboid //taking the length height and the width of the cuboid printf("\nPlease Enter Length, Width and Height of a Cuboid\n"); /*scanning the height, width and the length of the cuboid*/ scanf("%f %f %f",&l, &w, &h); //calculating the surface area of the cuboid SA = 2 * (l * w + l * h + w * h); //calculating the volume of the cuboid vol = l * w * h; LSA = 2 * h * (l + w); //printing the surface area of the cuboid. printf("\n The Surface Area of a Cuboid = %.2f\n",SA); //printing the volume of the cuboid. printf("\n The volume of a Cuboid = %.2f\n",vol); //printing the lateral surface area of the cuboid. printf("\n The Lateral Surface Area of a Cuboid = %.2f\n",LSA); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- l = it will hold the integer value for the input length of the Cuboid.
- w = it will hold the integer value for the input width of the Cuboid.
- h = it will hold the integer value for the input height of the Cuboid.
- vol = it will hold the value of the volume of the Cuboid.
Taking the input length, width, and height of the cuboid from the user.
Calculating the surface area & volume of the Cuboid.
Printing the volume and surface area of the Cuboid.