write two functions that return the volume and weight of a disc. use the main fu
ID: 3712009 • Letter: W
Question
write two functions that return the volume and weight of a disc. use the main function EXACTLY as below.volume of a disc=((3.142*diameter*diameter)/4)*thickness.
weight of a disc=volume*density of the disc
#include<stdio.h>
float disc_vol(float,float);
float dist_wt(float,float);
int main ()
{
float dia, thickness, density vol, wt;
printf("enter the diameter of the disc ");
scanf("%f",&dia);
printf("enter the thickness of the disc ");
scanf("%f", &thickness);
printf("enter the density of the disc ");
scanf("%f",&density);
vol = dis_vol(dia,thickness);
wt=disc_wt(vol,density);
printf("The volume of the disc is %f ", vol);
printf("the weight of the disc is %f ",wt);
printf("bye ");
}
sample output that you can check against
enter the diameter of the disc
5
enter the thickness of the disc
3
enter the density of the disc
3.8
the volume of the disc is 58.9124
the weight of the disc 223.867
bye
I need to write the functions below and make sure they're working ...what are the correct functions ? write two functions that return the volume and weight of a disc. use the main function EXACTLY as below.
volume of a disc=((3.142*diameter*diameter)/4)*thickness.
weight of a disc=volume*density of the disc
#include<stdio.h>
float disc_vol(float,float);
float dist_wt(float,float);
int main ()
{
float dia, thickness, density vol, wt;
printf("enter the diameter of the disc ");
scanf("%f",&dia);
printf("enter the thickness of the disc ");
scanf("%f", &thickness);
printf("enter the density of the disc ");
scanf("%f",&density);
vol = dis_vol(dia,thickness);
wt=disc_wt(vol,density);
printf("The volume of the disc is %f ", vol);
printf("the weight of the disc is %f ",wt);
printf("bye ");
}
sample output that you can check against
enter the diameter of the disc
5
enter the thickness of the disc
3
enter the density of the disc
3.8
the volume of the disc is 58.9124
the weight of the disc 223.867
bye
I need to write the functions below and make sure they're working ...what are the correct functions ? write two functions that return the volume and weight of a disc. use the main function EXACTLY as below.
volume of a disc=((3.142*diameter*diameter)/4)*thickness.
weight of a disc=volume*density of the disc
#include<stdio.h>
float disc_vol(float,float);
float dist_wt(float,float);
int main ()
{
float dia, thickness, density vol, wt;
printf("enter the diameter of the disc ");
scanf("%f",&dia);
printf("enter the thickness of the disc ");
scanf("%f", &thickness);
printf("enter the density of the disc ");
scanf("%f",&density);
vol = dis_vol(dia,thickness);
wt=disc_wt(vol,density);
printf("The volume of the disc is %f ", vol);
printf("the weight of the disc is %f ",wt);
printf("bye ");
}
sample output that you can check against
enter the diameter of the disc
5
enter the thickness of the disc
3
enter the density of the disc
3.8
the volume of the disc is 58.9124
the weight of the disc 223.867
bye
I need to write the functions below and make sure they're working ...what are the correct functions ?
Explanation / Answer
Answer:
functions can be written as below:
float dis_vol(float dia,float thickness) // takes diameter and thickness as parameter
{
return ((3.142*dia*dia)/4)*thickness; // returns the disc volume to the function
}
float disc_wt(float vol,float density) //takes the volume and density as the parameter
{
return vol*density; //returns the disc weight to the function
}
THUS THE WHOLE PROGRAM CAN BE WRITTEN AS:
#include<stdio.h>
float dis_vol(float dia,float thickness)
{
return ((3.142*dia*dia)/4)*thickness;
}
float disc_wt(float vol,float density)
{
return vol*density;
}
int main ()
{
float dia, thickness, density,vol, wt;
printf("enter the diameter of the disc ");
scanf("%f",&dia);
printf("enter the thickness of the disc ");
scanf("%f", &thickness);
printf("enter the density of the disc ");
scanf("%f",&density);
vol = dis_vol(dia,thickness); //function dis_vol is called here and assigned to variable vol
wt=disc_wt(vol,density); // function disc_wt is called here and assigned to variable wt
printf("The volume of the disc is %f ", vol); //prints the volume calculated by the function
printf("the weight of the disc is %f ",wt); //prints the weight calculated by the function
printf("bye ");
}
output:
enter the diameter of the disc
5
enter the thickness of the disc
3
enter the density of the disc
3.8
the volume of the disc is 58.9124
the weight of the disc 223.867
bye
!! hope you like my answer !! please leave a comment for more explanation or any doubts !!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.