Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Volume Functions. For each of the shapes listed below, write a separate function

ID: 3531370 • Letter: V

Question

Volume Functions. For each of the shapes listed below, write a separate function that will compute the volume. If any of the dimensions passed to the function is less than zero, the function should return a volume of zero. Write a main() function to test your volume functions.


a. Right circular cylinder: f(r,h) = (pi)r^2h, where r = radius and h = height.

b. Right circular cone: g(r,h) = (1/3)(pi)r^2h, where r = radius and h = height.

c. Rectangular pyramid: h(l, w, h) = 1/3(l * w * h), where l = length of base, w = width of base, and h = height of pyramid.

Explanation / Answer

include<stdio.h>

include<math.h>

include<stdlib.h>


#define PI 3.14


main()

{

int i;

printf(" Enter 1 for cyliner , 2 for cone or 3 for pyramid :")

scanf("%d",&i);

if(i==1) cylinder();

if(i==2) cone();

if(i==3) pyramid();

}


void cylinder()

{

double rad,height,vol;

printf(" Enter the radius of the cylinder:");

scanf("%lf",&rad);

printf(" Enter the height of the cylinder:");

scanf("%lf",&height);

vol = PI*rad*rad*height;

printf(" The Volume of the Right circular cylinder is %lf",vol);

}



void cone()

{

double rad,height,vol;

printf(" Enter the radius of the cone:");

scanf("%lf",&rad);

printf(" Enter the height of the cone:");

scanf("%lf",&height);

vol = PI*rad*rad*height/3.0;

printf(" The Volume of the Right circular cone is %lf",vol);

}


void pyramid()

{

double len,wid,height,vol;

printf(" Enter the length of the pyramid:");

scanf("%lf",&len);

printf(" Enter the width of the pyramid:");

scanf("%lf",&wid);

printf(" Enter the height of the pyramid:");

scanf("%lf",&height);

vol = len*wid*height/3.0;

printf(" The Volume of the Rectangular Pyramid is %lf",vol);

}