Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define PI 3.14159265358979323846
- int main() {
- long long height, radius;
- printf("Input radius: ");
- scanf("%lld", &radius); //get the radius of the cylinder
- printf("Input height: ");
- scanf("%lld", &height); //get the height of the cylinder
- //we use double data type because the result will have decimals
- double volume_double = radius*radius*PI*height; //calculate the volume of the cylinder
- //output the volume of the cylinder
- //we use %lf format specifier because we use double data type
- printf("Volume of Cylinder (double): %.10lf\n", volume_double);
- //if we were using a float data type we would use %f
- float volume_float = radius*radius*PI*height; //calculate the volume of the cylinder
- printf("Volume of Cylinder (float): %.10f", volume_float);
- return 0;
- //note the precision difference between float and double
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement