C Program to Find Volume and Surface Area of Cuboid

This is a C Program to find the volume and surface area of cuboids.

Problem Description

This C Program calculates the volume and surface area of cuboids.

Problem Solution

The formula used in this program are surfacerea= 2(w * l + l * h + h * w) where w is width, l is length and h is a height of the cuboids. volume = width * length * height.

Program/Source Code

Here is source code of the C Program to Find the volume and surface area of cuboids.The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
 * C Program to Find the Volume and Surface Area of Cuboids
 */
#include <stdio.h>
#include <math.h>
 
int main()
{
    float width, length, height;
    float surfacearea, volume, space_diagonal;
 
    printf("Enter value of width, length & height of the cuboids:\n");
    scanf("%f%f%f", &width, &length, &height);
    surfacearea = 2 *(width * length + length * height +
    height * width);
    volume = width * length * height;
    space_diagonal = sqrt(width * width + length * length +
    height * height);
    printf("Surface area of cuboids is: %.3f", surfacearea);
    printf("\n Volume of cuboids is : %.3f", volume);
    printf("\n Space diagonal of cuboids is : %.3f", space_diagonal);
    return 0;
}
Program Explanation

In this C program, library function defined in <math.h> header file is used to compute mathematical functions. We are reading the ‘width’, ‘length’ and ‘height’ values of cuboids. To find the surface area and the volume, the following formulas are used.

advertisement
advertisement

Surface area= 2(width * length + length * height + height * width)

Volume = width * length * height

Diagonal =sqrt(width * width + length * length + height * height).

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
Runtime Test Cases
 
Output:
$ cc pgm28.c -lm
$ a.out
Enter value of width, length & height of the cuboids :
 22 23 24
Surface area of cuboids is: 3172.000
Volume of cuboids is : 12144.000
Space diagonal of cuboids is : 39.862

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

advertisement
If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.