Lets write a C program to calculate Surface area, Volume and Lateral Surface area of a Cube.
Related Read:
Basic Arithmetic Operations In C
Formula To Calculate Surface Area, Volume and Lateral Surface area of a Cube
Note: If we know the length of any side of the cube, we can calculate the surface area and lateral surface area by using formula shown below.
Surface Area of a Cube
surface_area = 6 * (l * l);
Lateral Surface Area of a Cube
lateral_surface_area = 4 * (l * l);
Volume of a Cube
volume= l * l * l;
where l is value of length of any side of a cube.
The amount of space present inside the cube(3 dimensional cube) is called the volume of that cube.
Source Code: C Program to Find Surface Area and Volume of a Cube
#include < stdio.h > int main() { float l, SA, volume, LSA; printf("Enter length of any side of a cube\n"); scanf("%f", &l); SA = 6 * (l * l); volume = l * l * l; LSA = 4 * (l * l); printf("Surface Area of the cube = %f\n", SA); printf("Volume of the cube = %f\n", volume); printf("Lateral Surface Area of the cube = %f\n", LSA); return 0; }
Output 1:
Enter length of any side of a cube
3
Surface Area of the cube = 54.000000
Volume of the cube = 27.000000
Lateral Surface Area of the cube = 36.000000
Output 2:
Enter length of any side of a cube
5
Surface Area of the cube = 150.000000
Volume of the cube = 125.000000
Lateral Surface Area of the cube = 100.000000
C Program to Find Surface Area and Volume of a Cube
[youtube https://www.youtube.com/watch?v=rqAH-E_dR0w]
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert