fork download
  1. #include <stdio.h>
  2. /* Kanyaphat Ongsantpap*/
  3. /* 66070503015 CHE */
  4.  
  5.  
  6. float cubeVolume();
  7. float cylinderVolume();
  8. float prismVolume();
  9. float sphereVolume();
  10. float pyramidvolume();
  11. float coneVolume();
  12. #define PI 3.14
  13. float cube ;
  14. float cylinder, prism, sphere, pyramid,cone;
  15. float a, rC, h, base, height, rS, basep, heightp, rCone, hcone;
  16. int main(void) {
  17. int i;
  18. printf("Press 1 to find Volume of Cube\nPress 2 to find Volume of Cylinder\nPress 3 to find Volume of Prism\nPress 4 to find Volume of sphere\nPress 5 to find Volume of Pyramid\nPress 6 to find Volume of Cone\nPress 0 to exit the program\n");
  19. scanf("%d", &i);
  20. switch(i){
  21. case 1: {
  22.  
  23. printf("Side of the cube:");
  24. scanf("%f", &a);
  25. float cube = cubeVolume();
  26. if(cube >= 0.01){
  27. printf("The Volume of Cube is %0.2f", cube);
  28. }
  29. }
  30. break;
  31. case 2:{
  32. printf("Radius of the Cylinder:");
  33. scanf("%f", &rC);
  34. printf("Height of the Cylinder:");
  35. scanf("%f", &h);
  36. float cylinder = cylinderVolume();
  37. if(cylinder >= 0.01){
  38. printf("The Volume of Cylinder is %0.2f", cylinder);
  39. }
  40. }
  41. break;
  42. case 3:{
  43. printf("Area base of pryamid:");
  44. scanf("%f", &base);
  45. printf("Height of the Prism:");
  46. scanf("%f", &height);
  47. float prism = prismVolume();
  48. if(prism >= 0.01){
  49. printf("The Volume of Prism is %0.2f", prism);
  50. }
  51. }
  52. break;
  53. case 4:{
  54. printf("Radius of the Sphere:");
  55. scanf("%f", &rS);
  56. float sphere = sphereVolume();
  57. if(sphere >= 0.01){
  58. printf("The Volume of Sphere is %0.2f", sphere);
  59. }
  60. }
  61. break;
  62. case 5:{
  63. printf("Base of the Pyramid:");
  64. scanf("%f", &basep);
  65. printf("Height of the Pyramid:");
  66. scanf("%f", &heightp);
  67. float pyramid = pyramidvolume();
  68. if(pyramid >= 0.01){
  69. printf("The Volume of Pyramid is %0.2f", pyramid);
  70. }
  71. }
  72. break;
  73. case 6:{
  74. printf("Radius of the Cone:");
  75. scanf("%f", &rCone);
  76. printf("Height of the Cone:");
  77. scanf("%f", &hcone);
  78. float cone = coneVolume();
  79. if(cone >= 0.01){
  80. printf("The Volume of Cone is %0.2f", cone);
  81. }
  82. }
  83. break;
  84. case 0:
  85. printf("Exiting the program");
  86. break;
  87. }
  88. return 0;
  89.  
  90. }
  91. float cubeVolume(){
  92. return a*a*a;
  93. }
  94. float cylinderVolume(){
  95. return PI*rC*rC*h;
  96. }
  97. float prismVolume(){
  98. return base*height;
  99. }
  100. float sphereVolume(){
  101. return 4.00/3.00*PI*rS*rS*rS;
  102. }
  103. float pyramidvolume(){
  104. return 1.00/3.00*basep*heightp;
  105. }
  106. float coneVolume(){
  107. return 1.00/3.00*PI*rCone*rCone*hcone;
  108. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Press 1 to find Volume of Cube
Press 2 to find Volume of Cylinder
Press 3 to find Volume of Prism
Press 4 to find Volume of sphere
Press 5 to find Volume of Pyramid
Press 6 to find Volume of Cone
Press 0 to exit the program