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 finds the Greatest Common Divisor (GCD) of two given numbers. Problem Statement Write a C program that...
This C program calculates the roots of a quadratic equation of the form ax^2 + bx + c = 0....
This C program allows you to find the length of a linked list, which is the number of nodes present...