Kevin321888999

Lab 3 part A

Mar 1st, 2022
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 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.   return num1/2; //definition
  7. }
  8. double pow(double num1, double num2);// radius^2
  9. double cbrt(double num1 ){//function to find radius^3.
  10.   return num1*num1*num1;
  11. }
  12. double SA(double num1, double num2, double num3){//function to find surface area.
  13.   double result;
  14.   result=num1*num2*num3;
  15.   return result;
  16.   }
  17. double circum(double num1, double num2){
  18. double result; //For circumference
  19. result= num1* num2;
  20. return result;
  21. }
  22. double vol(double num1, double num2, double num3, double num4){
  23.   double result;
  24.   result=((num1*num2)/num3)*num4;
  25.   return result;
  26.   }
  27.  
  28. int main(void){
  29. double D; //declare the diameter variable as double
  30. double Y=2;//declare the variables
  31. int G=3;
  32. int H=4;
  33.  
  34.  
  35. for(double i=0;i<=3;i++)//The For loop limits the amount of loops to 4 although it says 3.
  36. { printf("\n\nEnter the Diameter: ");
  37.  scanf("%lg",&D);
  38.  
  39.   if(D>=0){
  40.     double Radius;
  41.     Radius= R(D);
  42.      double radius2;
  43.     radius2= pow(Radius, Y);
  44.     double radius3;
  45.     radius3= cbrt(Radius);
  46.     double surfacearea;
  47. surfacearea=SA(H,Pi,radius2);
  48.      double circumference;
  49.     circumference=circum(Pi,D);
  50.     double volume;
  51.    volume= vol(H,Pi,G,radius3);  
  52.    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);
  53. }
  54.    
  55. if (D<0){ double Radius;
  56.     Radius= R(D);
  57.      double radius2;
  58.     radius2= pow(Radius, Y);
  59.     double radius3;
  60.     radius3= cbrt(Radius);
  61.     double surfacearea;
  62. surfacearea=SA(H,Pi,radius2);
  63.      double circumference;
  64.     circumference=circum(Pi,D);
  65.     double volume;
  66.    volume= vol(H,Pi,G,radius3);
  67.   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\n TOO LOW, STOP! ",D,Radius, surfacearea,circumference,volume);return 1;}
  68. else;}
  69. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment