accept dimensions of a cylinder and print the surface area and volume (hint : surface area = 2 pai r square +2 pai r h ,volume = pai r square h
Answers
Explanation:
Solution:
SA = 2 × π × r2 + 2 × π × r × h
SA = 2 × 3.14 × 42 + 2 × 3.14 × 4 × 3
SA = 6.28 × 16 + 6.28 × 12
SA = 100.48 + 75.36
SA = 175.84
Complete Question: Write a program that accepts dimensions of a cylinder as input and prints the surface area and volume of the cylinder. (Hint: Surface Area = 2πr² + 2πrh and Volume = πr²h)
// C Program which takes the dimensions of a cylinder as input, and prints the surface area and volume of the cylinder as output:
#include <stdio.h>
int main()
{
// Declaring two variables which are radius and height in float data type.
// Here r represents radius and h represents height.
float r, h;
// Printing a prompt to take input from the user.
printf("Enter the values of radius and height of cylinder\n");
// Taking the values of the radius and height of the Cylinder as input.
scanf("%f %f", &r, &h);
//Calculating the values of Surface Area and Volume, assuming π = 3.14
float Area=(2 * 3.14 * r * h) + (2 * 3.14 * r * r);
float Volume = (3.14 * r * r * h);
// Printing the values of the Surface Area and Volume of the Cylinder.
printf("The Surface Area of the cylinder is equal to %f\n",Area );
printf("The Volume of the cylinder is equal to %f\n",Volume);
return 0;
}
Step-by-step Explanation:
1. Declare two variables 'r' and 'h' in float data type for radius and height respectively.
2. Take the values of the radius and height of the cylinder as input from the user using the scanf function.
3. Now calculate the values of the Surface Area and Volume of the cylinder using the formula and store these values in the two new variables, 'Area' and 'Volume' respectively.
4. Now print the values of Surface Area and Volume using the printf function.
#SPJ2