Read the height, width, and length of cuboids from the user, and calculate the surface area, volume, and space diagonal of cuboids.
Surface area of cuboids:
A cuboid has 6 rectangular faces. To find the surface area of a cuboid, add the areas of all 6 faces. Consider that the length is l, width is w, and height is h of the prism and then the formula to calculate the Surface area of cuboids will be: 2lw + 2lh + 2hw
Volume of cuboids:
The formula to calculate volume of cuboids (V) = whl
Space diagonal of cuboids: √(l2 + b2 +h2)
Program:
The source code to calculate the surface area, volume, and space diagonal of cuboids is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
// C program to calculate the surface Area,
// volume, and space diagonal of cuboids.
#include <stdio.h>
#include <math.h>
int main()
{
float height = 0;
float width = 0;
float length = 0;
float volume = 0;
float area = 0;
float diagonal = 0;
printf("Enter the height: ");
scanf("%f", &height);
printf("Enter the width: ");
scanf("%f", &width);
printf("Enter the length: ");
scanf("%f", &length);
diagonal = sqrt(width * width) + (length * length) + (height * height);
area = 2 * (width * length) + (length * height) + (height * width);
volume = width * length * height;
printf("Volume of Cuboids is : %f\n", volume);
printf("Surface area of Cuboids is : %f\n", area);
printf("Space diagonal of Cuboids is: %f\n", diagonal);
return 0;
}
Output:
RUN 1:
Enter the height: 10
Enter the width: 20
Enter the length: 30
Volume of Cuboids is : 6000.000000
Surface area of Cuboids is : 1700.000000
Space diagonal of Cuboids is: 1020.000000
RUN 2:
Enter the height: 1.0
Enter the width: 2.0
Enter the length: 3.0
Volume of Cuboids is : 6.000000
Surface area of Cuboids is : 17.000000
Space diagonal of Cuboids is: 12.000000
RUN 3:
Enter the height: 1.2
Enter the width: 11.23
Enter the length: 4.5
Volume of Cuboids is : 60.641998
Surface area of Cuboids is : 119.945992
Space diagonal of Cuboids is: 32.919998
Explanation:
Here, we read the value of height, width, and length from the user. Then we calculated the surface area, volume, and space diagonal of cuboids using standard formulas.
Read the height, width, and length of cuboids from the user, and calculate the surface area, volume, and space diagonal of cuboids.
Surface area of cuboids:
A cuboid has 6 rectangular faces. To find the surface area of a cuboid, add the areas of all 6 faces. Consider that the length is l, width is w, and height is h of the prism and then the formula to calculate the Surface area of cuboids will be: 2lw + 2lh + 2hw
Volume of cuboids:
The formula to calculate volume of cuboids (V) = whl
Space diagonal of cuboids: √(l2 + b2 +h2)
Program:
The source code to calculate the surface area, volume, and space diagonal of cuboids is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
Output:
Explanation:
Here, we read the value of height, width, and length from the user. Then we calculated the surface area, volume, and space diagonal of cuboids using standard formulas.
need an explanation for this answer? contact us directly to get an explanation for this answer