Defining and Using Functions Formula for the volume of a sph

Defining and Using Functions

Formula for the volume of a sphere: (4/3) × pi × radius3

Define a function that welcomes a user to your application and explains its purpose

Define a function that asks the user for the radius of a sphere

Define a function that, given the radius of a sphere, calculates and returns its volume

Use your functions

Solution

#include <stdio.h>

void welcome() //welcome function
{
   printf(\"Welcome to My Application of Volume Computation\");
}
double inputRadius() //function to input radius of sphere
{
   double radius;
   printf(\"\ Enter the radius of sphere\");
   scanf(\"%lf\",&radius);
   return radius;
}
double computeVolume(double radius) //function to compute volume of sphere
{
   double pi,volume;
   pi = 3.1412;
   volume = (4/3) * pi * radius;
   return volume;
}
int main(void)
{
   double radius,volume;
   welcome();
  
   radius = inputRadius();
  
   volume = computeVolume(radius);
  
   printf(\"\ Volume of the sphere : %.2lf\",volume);
  
   return 0;
}

output:

Defining and Using Functions Formula for the volume of a sphere: (4/3) × pi × radius3 Define a function that welcomes a user to your application and explains it

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site