C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Surface Area of a Cylinder

Introduction (Cylinder Surface Area)

A cylinder is a 3D solid shape with two parallel circular bases connected by a curved surface.
Examples in real life include cans, pipes, and water tanks.

The surface area of a cylinder has two parts:

  1. Curved Surface Area (CSA): 2πrh
  2. Total Surface Area (TSA): 2πr (r + h)

where

  • r = radius of the base
  • h = height of the cylinder
  • π (pi) ≈ 3.14159

In this program, we calculate the Total Surface Area (TSA).

 

C Program: Surface Area of a Sphere

C

#include <stdio.h>

#define PI 3.14159   // Define constant PI

 

int main() {

    float radius, height, surface_area;

 

    // Input radius and height

    printf("Enter the radius of the cylinder: ");

    scanf("%f", &radius);

 

    printf("Enter the height of the cylinder: ");

    scanf("%f", &height);

 

    // Calculate total surface area

    surface_area = 2 * PI * radius * (radius + height);

 

    // Display result

    printf("Surface Area of Cylinder = %.2f\n", surface_area);

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter the radius of the cylinder: 5
Enter the height of the cylinder: 10
Surface Area of Cylinder = 471.24


OUTPUT 2 :
Enter the radius of the cylinder: 3.5
Enter the height of the cylinder: 8
Surface Area of Cylinder = 254.47


Explanation

  1. The program takes radius and height as input.
  2. Formula applied: 2 × π × r × (r + h).
  3. PI is defined using #define.
  4. Output is displayed with two decimal precision.