C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Area and Circumference of a Circle

Introduction

A circle is a closed 2D shape where every point on the boundary is equidistant from the center.
Two important properties of a circle are its area (the space enclosed) and circumference (the distance around it).

The formulas are:

Area=π×r2  

Circumference=2×π×r

Where:

  • r = radius of the circle
  • π(pi) ≈ 3.14159

In this program, we take the radius of a circle from the user and compute both the area and circumference.

 

C Program: Area and Circumference of a Circle

C

#include <stdio.h>   // Standard I/O header

#define PI 3.14159   // Defining constant value of PI

 

int main() {

    float radius, area, circumference;

 

    // Input from user

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

    scanf("%f", &radius);

 

    // Calculations

    area = PI * radius * radius;

    circumference = 2 * PI * radius;

 

    // Output results

    printf("Area of the circle          = %.2f\n", area);

    printf("Circumference of the circle = %.2f\n", circumference);

 

    return 0; // Successful termination

}

Output

 
OUTPUT 1 :
Enter the radius of the circle: 7
Area of the circle          = 153.94
Circumference of the circle = 43.98

OUTPUT 2 :
Enter the radius of the circle: 3.5
Area of the circle          = 38.48
Circumference of the circle = 21.99

Explanation :

  1. #define PI 3.14159
    • Defines a constant value for π (pi).
  2. Variable declaration
    • float radius, area, circumference;
  3. Input
    • User enters the radius of the circle.
  4. Formulas applied
    • area = PI * radius * radius;
    • circumference = 2 * PI * radius;
  5. Output
    • Results displayed with %.2f → two decimal places.