Kevin321888999

Lab 3 part A

Feb 28th, 2022
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. #include <stdio.h>// library standard
  2. #include <math.h>
  3. #define Pi 3.14159265
  4.  
  5. double R(num1) {//function to find radius
  6.   double result;
  7.   result= num1/2;
  8.   return result; //definition
  9. }
  10. double pow(double num1, double num2);// radius^2
  11. double cbrt(double num1 ){//function to find radius^3.
  12. double result;
  13.   result= num1*num1*num1;
  14.   return result;
  15. }
  16. double SA(double num1, double num2, double num3){//function to find surface area.
  17.   double result;
  18.   result=num1*num2*num3;
  19.   return result;
  20.   }
  21. double circum(double num1, double num2){
  22. double result; //For circumference
  23. result= num1* num2;
  24. return result;
  25. }
  26. double vol(double num1, double num2, double num3, double num4){
  27.   double result;
  28.   result=((num1*num2)/num3)*num4;
  29.   return result;
  30.   }
  31.  
  32.  
  33. int main(void){
  34.  double D; //declare the diameter variable as double
  35.    double Y=2;
  36.    int G=3;
  37.   int H=4;
  38.  
  39. for(double i=0;i<=3;i++)//The For loop limits the amount of loops to 4 although it says 3.
  40. { printf("\n\nEnter the Diameter: ");
  41.  scanf("%lg",&D);
  42.   if(D>=0){
  43.     double Radius;
  44.     Radius= R(D);//find the Radius, Radius^2, and Radius^3 inorder to plug them into the equations for circumference, surface area, radius, and volume.
  45.      double radius2;
  46.     radius2= pow(Radius, Y);
  47.     double radius3;
  48.     radius3= cbrt(Radius);
  49.     double surfacearea;
  50. surfacearea=SA(H,Pi,radius2);//Function call.
  51.      double circumference;
  52.     circumference=circum(Pi,D);//function call for circum.
  53.     double volume;
  54.    volume= vol(H,Pi,G,radius3);  //function call for vol.
  55.    printf("\nThe measurements of a sphere: \nThe Diameter is: %lg.\n And the Radius is: %lg. \n Surface Area is: %lg.\n The Circumference is: %lg.\n The Volume is: %lg",D,Radius, surfacearea,circumference,volume);
  56. }
  57.    
  58. else;
  59. return 0;}}
Advertisement
Add Comment
Please, Sign In to add comment