[Tutorial 7] 8.Calculate the volume of a cylinder. PI * r2 h
#include <stdio.h>
#define PI 3.14159
int main()
#define PI 3.14159
int main()
{
float radius, height, volume;
float radius, height, volume;
/* Input radius and height from the user*/
printf("Enter the radius of the cylinder: ");
scanf("%f", &radius);
printf("Enter the height of the cylinder: ");
scanf("%f", &height);
printf("Enter the radius of the cylinder: ");
scanf("%f", &radius);
printf("Enter the height of the cylinder: ");
scanf("%f", &height);
/* Calculate volume*/
volume = PI * radius * radius * height;
/* Display the volume*/
printf("The volume of the cylinder is: %.2f cubic units\n", volume);
return 0;
}
volume = PI * radius * radius * height;
/* Display the volume*/
printf("The volume of the cylinder is: %.2f cubic units\n", volume);
return 0;
}
This program prompts the user to enter the radius and height of the cylinder, then calculates and displays the volume. Make sure to save the file with a .c extension (e.g., cylinder_volume.c) before compiling and running it.
Comments
Post a Comment