Write a program that reads the values for the width, length, and height of a rectangular box using three variables of double type in the function main(). Pass values of these variables to a function, which calculates the volume and surface area for six sides of the box. The volume and surface area of the box passed back from two other arguments of this function are printed out in the function main(). Check your program with the user input for the width, length, and height of 2, 3, 4 meters, respectively.
#include <stdio.h>
void calculataVolumeAndArea(double w, double l, double h){
double volume=l*w*h;
double area=2*(l*w)+2*(l*h)+2*(h*w);
printf("\nVolume of the Box = %lf",volume);
printf("\nSurface Area = %lf",area);
}
int main()
{
double width, length, height;
printf("\nEnter width: ");
scanf("%lf",&width);
printf("\nEnter length: ");
scanf("%lf",&length);
printf("\nEnter height: ");
scanf("%lf",&height);
calculataVolumeAndArea(width,length,height);
return 0;
}
Comments
Leave a comment