BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to calculate Area and Circumference of Circle

Last Updated: May 19, 2024 by Chaitanya Singh | Filed Under: C Programs

In this tutorial, you will learn how to write a C program to calculate area and circumference of a circle. This program is pretty simple as both the circle area and circle circumference need radius value.

Formula to calculate are and circumference of circle

Here 3.14159 is the value of Pi, represented by symbol π.

Area of circle = Pi * radius * radius
Circumference of circle = 2 * Pi * radius

Program to calculate Area and Circumference based on user input

This program takes radius value from the user. The program prompts user to enter the radius value and calculates the area and circumference of circle based on the entered value.

#include <stdio.h>
#define PI 3.14159

int main() {
float radius, area, circumference;

//Prompt user to enter the radius of circle
printf("Enter the radius of the circle: ");
scanf("%f", &radius);

// Calculate area and circumference of circle
area = PI * radius * radius;
circumference = 2 * PI * radius;

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

return 0;
}

Output: User enters the radius value as 2 and program calculates and prints the area and circumference using this entered value.

Enter the radius of the circle: 2
Area of the circle: 12.57
Circumference of the circle: 12.57

Explanation:

  1. Include Standard Libraries:
    • #include <stdio.h> for standard input and output functions such as printf and scanf.
    • #define PI 3.14159 defines the value of π (pi) for calculating the area and circumference of circle.
  2. Declare Variables:
    • float radius, area, circumference; These variables hold the radius, area, and circumference of the circle.
  3. User Input:
    • printf("Enter the radius of the circle: "); prompts the user to enter the radius of the circle.
    • scanf("%f", &radius); reads and stores the entered value in radius variable.
  4. Calculate Area and Circumference:
    • area = PI * radius * radius; This formula is used for area calculation.
    • circumference = 2 * PI * radius; This formula is used for circumference calculation.
  5. Print Results:
    • printf("Area of the circle: %.2f\n", area); prints the area with two decimal places.
    • printf("Circumference of the circle: %.2f\n", circumference); prints the circumference with two decimal places.
  6. Return Statement:
    • return 0; indicates that the program executed successfully.
❮ C TutorialC Programs ❯

Top Related Articles:

  1. C Program to concatenate two strings without using strcat
  2. C Program to read and print employee details using structure
  3. C Program to print cube of a number upto an integer
  4. C Program to Read the First Line From a File
  5. C program to calculate and print the value of nCr

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. Tumelo says

    March 22, 2016 at 5:30 PM

    can you guys help me out here.

    write a console program that calculate the area a and circuference c of the circle

    a= p x r2
    c=2 x p x r

    you can send it on my email please.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap