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

Write a C program NOT C++ Write a description for each step Calculate the volume

ID: 3834782 • Letter: W

Question

Write a C program NOT C++

Write a description for each step

Calculate the volume of a spherical bottom flask pictured below. Consider the bottom to be a partially filled sphere and the top part to be a cylinder. Define PI as a symbolic constant using an appropriate pre-processor command. In function main prompt the user for the radius of the spherical portion, and the radius and height of the cylindrical portion. Calculate volumes of the spherical portion, the cylindrical portion, and the total volume. Use the following formulas: Volume of cylinder: v = pi r^2h Volume of partially filled sphere: V = pi R^3 (2/3 (1 + cos theta)+ 1/3 cos theta(1 - cos^2 theta)) Print the individual volumes and total volume with two digits after the decimal point. Test with values R = 5 cm, r = 2 cm, and h = 8 cm.

Explanation / Answer

// C code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define pi 22/7

int main()
{
   // declaring variable
   float R,r,h,cylinderVolume,sphereVolume;
   float totalVolume;

   // taking input from user
   printf("Enter radius of Sphere: ");
   scanf("%f",&R);
   printf("Enter radius of cylinder: ");
   scanf("%f",&r);
   printf("Enter height of cylinder: ");
   scanf("%f",&h);

   // determine volumen of cylinder and sphere
   cylinderVolume = pi*r*r*h;

   // determine cos theta
   float costheta = sqrt(R*R-r*r)/R;
   sphereVolume = pi*R*R*R*((2.0/3)*(1+costheta) + (1.0/3)*costheta*(1- costheta*costheta));

   // determien total volume
   totalVolume = sphereVolume + cylinderVolume;

   printf("Volume of sphere: %0.2f ", sphereVolume);
   printf("Volume of cylinder: %0.2f ",cylinderVolume);
   printf("Total Volume: %0.2f ", totalVolume);
   return 0;
}


/*
output:

Enter radius of Sphere: 7
Enter radius of cylinder: 3
Enter height of cylinder: 5
Volume of sphere: 1362.73
Volume of cylinder: 135.00
Total Volume: 1497.73

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote