HomeC ProgrammingC Program to Find Volume and Surface Area of Cylinder

C Program to Find Volume and Surface Area of Cylinder

Intro

This C program calculates the volume and surface area of a cylinder using its radius and height. It demonstrates two functions to compute these values and ensures that the user provides valid input for the dimensions.

Problem statement

Given the radius and height of a cylinder, we need to find its volume and surface area.

C Program to Find Volume and Surface Area of Cylinder

#include <stdio.h>

#define PI 3.14159

int main() {
    float radius, height;
    float volume, surfaceArea;

    // Introduction
    printf("Program to calculate the volume and surface area of a cylinder\n\n");

    // Problem statement
    printf("Enter the radius of the cylinder: ");
    scanf("%f", &radius);
    printf("Enter the height of the cylinder: ");
    scanf("%f", &height);

    // Calculations
    volume = PI * radius * radius * height;
    surfaceArea = (2 * PI * radius * height) + (2 * PI * radius * radius);

    // Output
    printf("\nVolume of the cylinder: %.2f cubic units\n", volume);
    printf("Surface area of the cylinder: %.2f square units\n", surfaceArea);

    return 0;
}

How it works

  1. We start by including the necessary header file stdio.h for input/output operations.
  2. The constant PI is defined with the value 3.14159.
  3. Inside the main function, we declare the variables radius, height, volume, and surfaceArea as float data types.
  4. The program then prints an introduction explaining its purpose.
  5. It asks the user to enter the radius and height of the cylinder using printf and reads the input values using scanf.
  6. Next, the program calculates the volume of the cylinder using the formula volume = PI * radius * radius * height.
  7. Similarly, it calculates the surface area of the cylinder using the formula surfaceArea = (2 * PI * radius * height) + (2 * PI * radius * radius).
  8. Finally, the program displays the volume and surface area of the cylinder using printf.

Input / Output

C Program to Find Volume and Surface Area of Cylinder

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C program calculates the volume and surface area of a sphere using its radius. A sphere is a three-dimensional...
This C program converts a Roman numeral to a decimal number. Roman numerals are a system of numerical notation used...
This C program calculates the value of sin(x) using the Taylor series expansion. The Taylor series expansion is a mathematical...