✓ Link copied to clipboard
C 📅 June 30, 2026 ⏱ 5 min read

C Program to Calculate Area and Circumference of Circle

C Program to Calculate Area and Circumference of Circle

Calculating the area and circumference of a circle is a common task in geometry. So, let's say you have a circle with a radius of 5 units. You probably wanna find out how much space it covers (its area) and how long its boundary is (its circumference). This simple C program helps you do both.

A potential pitfall is using the wrong value of PI. Make sure you're using it right for accurate results. When you run this program, it asks for the circle's radius and then prints the area and circumference.

What You Need Before Writing the C Program for Calculating Area and Circumference of a Circle

Ensure you have these ready:

  • Basic understanding of printf and scanf functions
  • Knowledge of variables and data types like float
  • Using the math.h library for PI
  • Any C compiler such as GCC 9 or newer — or just run it in the EduSeekho online compiler

Source Code of C Program to Calculate the Area and Circumference of a Circle

Below is the full source code to calculate the area and circumference of a circle based on the given radius.

circle_area_circumference.cC▶ Run
#include <stdio.h>
#include <math.h>

int main() {
    float radius, area, circumference;
    const float PI = 3.14159;

    // Taking input from user
    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);

    // Calculating area
    area = PI * radius * radius;

    // Calculating circumference
    circumference = 2 * PI * radius;

    // Printing results
    printf("Area of the circle: %.2f\n", area);
    printf("Circumference of the circle: %.2f\n", circumference);

    return 0;
}

Try this code yourself — free

Run it in the EduSeekho online compiler. No setup needed.

▶ Open Compiler

Output of the Circle Area and Circumference Program

Here's what you should see when you run the program with a radius of 5:

OutputConsole▶ Run
Enter the radius of the circle: 5
Area of the circle: 78.54
Circumference of the circle: 31.42
Output of C Program to Calculate the Area and Circumference of a Circle
Output of C Program to Calculate the Area and Circumference of a Circle

Algorithm to Calculate Area and Circumference in C

To calculate the area and circumference, the program first reads the radius and then uses standard formulas for a circle.

  1. Read the radius from the user.
  2. Calculate the area using the formula PI * radius * radius.
  3. Calculate the circumference using 2 * PI * radius.
  4. Print the area and circumference.
flowchart TD
  A([Start]) --> B[/Read radius/]
  B --> C[area = PI * radius * radius]
  C --> D[circumference = 2 * PI * radius]
  D --> E[/Print area and circumference/]
  E --> F([End])
Flowchart: the algorithm step by step

How the Circle Area and Circumference Program Works

Let's break down each part of the code.

  • #include <stdio.h> and #include <math.h> are used to include standard input-output functions and mathematical constants.
  • We declare radius, area, and circumference as float for precise calculations.
  • PI is defined as a constant 3.14159.
  • The program prompts for the circle's radius with printf and reads it using scanf.
  • Calculates area using PI * radius * radius.
  • Calculates circumference with 2 * PI * radius.
  • Finally, it prints the results with precision up to two decimal points.
🧠

Quick Quiz — test your understanding

Tap an option to check your answer

What library is required to use the constant PI in C?

🎉Correct! The math.h library contains the constant PI.
🤔Not quite. Think about where mathematical constants are usually defined.

Time and Space Complexity of the C Program to Calculate Area and Circumference

Analyzing the performance of the program reveals the following:

Time Complexity: O(1). The program performs a constant number of operations: a multiplication for the area and another for the circumference, regardless of the input radius.

Space Complexity: O(1). It uses a fixed amount of memory for radius, area, circumference, and PI — all float variables.

⚠️

Common mistake: Forgetting to include the math.h library can lead to undefined behavior if you try using M_PI for PI.

Key takeaway: For accurate calculations, always use a consistent value of PI and the right data types.

FAQs About Calculating Area and Circumference in C

Here are some common questions students have:

Using a constant makes sure your calculations are accurate and consistent.
Yep, using double gives more precision, but float usually works fine for most stuff.
The program doesn’t check for negative values. It just assumes the input is valid.
For this, we use a defined constant for PI. If you need built-in constants or functions, the library is necessary.
Change the printf format specifier to show more decimals, like %.4f for four decimal places.

If you found this program helpful, check out these related programs:

Conclusion

Think about using double for even more precision if you need it. Next up, you might wanna look into calculating the volume of a sphere. If this program feels too easy, try extending it to handle multiple circles in one go!

Practice coding in C by trying out more programs. Test your skills with our C quiz and run the code in the C online compiler.