Advertisement
zenados

VolumeCylinder

Sep 13th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #define PI 3.14159265358979323846
  3.  
  4. int main() {
  5.     long long height, radius;
  6.     printf("Input radius: ");
  7.     scanf("%lld", &radius); //get the radius of the cylinder
  8.  
  9.     printf("Input height: ");
  10.     scanf("%lld", &height); //get the height of the cylinder
  11.  
  12.     //we use double data type because the result will have decimals
  13.     double volume_double = radius*radius*PI*height; //calculate the volume of the cylinder
  14.     //output the volume of the cylinder
  15.     //we use %lf format specifier because we use double data type
  16.     printf("Volume of Cylinder (double): %.10lf\n", volume_double);
  17.  
  18.     //if we were using a float data type we would use %f
  19.     float volume_float = radius*radius*PI*height; //calculate the volume of the cylinder
  20.     printf("Volume of Cylinder (float): %.10f", volume_float);
  21.  
  22.     return 0;
  23.     //note the precision difference between float and double
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement