Respuesta :
Answer / Explanation:
To answer this question, we first define the parameters which are,
Volume: This can be defined or refereed to the quantity of three-dimensional space enclosed by a closed surface. For the purpose of illustration, we can say that the space that a substance or shape occupies or contains. The SI used in measuring volume is mostly in cubic metre.
Therefore,
Volume, where Volume = base area x height x 1/3
where,
Base area = base length x base width
However, we also watch out for the division integer.
So moving forward to write the code solving the question, we have:
double Pyramid Volume (double baseLength, double baseWidth, double pyramid Height)
{
double baseArea = baseLength * baseWidth;
double vol = ((baseArea * pyramidHeight) * 1/3);
return vol;
}
int main() {
cout << "Volume for 1.0, 1.0, 1.0 is: " << PyramidVolume(1.0, 1.0, 1.0) <<
endl;
return 0;
}
Answer:
The problem demands a function PyramidVolume() in C language since printf() command exists in C language. Complete code, output and explanation is provided below.
Code in C Language:
#include <stdio.h>
double PyramidVolume(double baseLength, double baseWidth, double pyramidHeight)
{
return baseLength*baseWidth*pyramidHeight/3;
}
int main()
{
printf("Volume for 1.0, 1.0, 1.0 is: %.2f\n",PyramidVolume(1, 1, 1));
printf("Volume for 2.5, 5, 2.0 is: %.2f\n",PyramidVolume(2.5, 5, 2.0));
return 0;
}
Output:
Please also refer to the attached output results
Volume for 1.0, 1.0, 1.0 is: 0.33
Volume for 2.5, 5, 2.0 is: 8.33
Explanation:
A function PyramidVolume of type double is created which takes three inputs arguments of type double length, width and height and returns the volume of the pyramid as per the formula given in the question.
Then in the main function we called the PyramidVolume() function with inputs 1.0, 1.0, 1.0 and it returned correct output.
We again tested it with different inputs and again it returned correct output.
