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

Design a computer program that: A) Has a separate function which calculates the

ID: 3700056 • Letter: D

Question

Design a computer program that: A) Has a separate function which calculates the volume of a sphere. 1.The variable volume should be pointer type. B) The radius of the base and the height of the sphere are passed from the main function (What if you wanted that to be different?) 1. The separate function you wrote calculates the volume of the sphere and passes the result to the main function. C) The print statement should be given within the main function to print the volume of the sphere. (How would you create a separate function for printing?)

Explanation / Answer


/**
C program that prompts user to enter
radius of sphere and calculate the volume of
sphere using method passing radius and address of pointer
and then display volume on console
*/
//volume.c
//include header files
#include<stdio.h>
#include<conio.h>
//function prototype
void calVolume(float radius,float *volume);
//start of main function
int main()
{
   float radius;
   float volume=0;
   printf("Enter radius of sphere : ");
   //read radius
   scanf("%f",&radius);

   //calling calVoime with radius and address of volume
   calVolume(radius,&volume);

   printf("Volume of sphere : %5.2f",volume);

   getch();
   return 0;
}
/*The funciton takes the radius and pointer type volume
and calculates the volum of sphere*/
void calVolume(float radius ,float *volume)
{
   *volume=(4.0/3.0)*(3.14*radius*radius*radius);
}

Sample Output:

Enter radius of sphere : 9
Volume of sphere : 3052.08

Note :To calculate volume of sphere , only radius is required .

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