Find the area of a circle in C programming.

A circle is a closed figure where all points are equidistant from a central point called the center. The distance from the center to any point on the circle is called the radius. To find the area of a circle in C programming, we use the mathematical formula and implement it with proper input handling.

Syntax

area = ? * radius * radius

Where ? (pi) ? 3.14159 and radius is the distance from center to the edge of the circle.

Method 1: Using Fixed Radius Value

This example calculates the area using a predefined radius value −

#include <stdio.h>

int main() {
    float radius = 8.0;
    float area;
    float pi = 3.14159;
    
    area = pi * radius * radius;
    
    printf("Radius: %.2f<br>", radius);
    printf("Area of circle: %.2f<br>", area);
    
    return 0;
}
Radius: 8.00
Area of circle: 201.06

Method 2: Using User Input

This approach takes the radius as input from the user −

#include <stdio.h>

int main() {
    float radius, area;
    float pi = 3.14159;
    
    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);
    
    area = pi * radius * radius;
    
    printf("Area of circle with radius %.2f is: %.2f<br>", radius, area);
    
    return 0;
}
Enter the radius of the circle: 5.5
Area of circle with radius 5.50 is: 95.03

Method 3: Using Math Library for Precise ?

For more accurate calculations, we can use the M_PI constant from math.h −

Installation: No additional installation required. The math.h library is part of standard C.

#include <stdio.h>
#include <math.h>

int main() {
    double radius = 10.0;
    double area;
    
    area = M_PI * radius * radius;
    
    printf("Using precise ? value:<br>");
    printf("Radius: %.2f<br>", radius);
    printf("Area: %.6f<br>", area);
    
    return 0;
}
Using precise ? value:
Radius: 10.00
Area: 314.159265

Comparison

Method ? Value Precision Use Case
Fixed Value 3.14159 5 decimal places Simple calculations
M_PI Constant 3.141592653589793 15+ decimal places Precise calculations

Key Points

  • Always use float or double for radius and area to handle decimal values
  • The M_PI constant provides higher precision than manually defining ?
  • Format output using %.2f for better readability

Conclusion

Calculating the area of a circle in C is straightforward using the formula ? × r². For basic programs, use a fixed ? value, but for precise calculations, prefer the M_PI constant from math.h library.

Updated on: 2026-03-15T12:04:18+05:30

13K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements