Google News
logo
C Program to calculate Area and Circumference of Circle

Formula to calculate are and circumference of circle :


Here 3.14 is the value of Pi, represented by symbol π. For the simplicity purpose, we are taking the Pi value as 3.14, to calculate accurate results take value as 22/7.
Area of circle = 3.14 * radius * radius
Circumference of circle = 2 * 3.14 * radius​

In the following example of C program to calculate the area and circumference of a circle :

Program :
#include <stdio.h>

#define PI 3.14159265359

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

    printf("Enter the radius of the circle: ");
    scanf("%lf", &radius);

    area = PI * radius * radius;
    circumference = 2 * PI * radius;

    printf("Area of the circle: %.2lf\n", area);
    printf("Circumference of the circle: %.2lf\n", circumference);

    return 0;
}
Output :
Enter the radius of the circle: 25
Area of the circle: 1963.50
Circumference of the circle: 157.08
Explanation :

* We start by declaring three variables: radius to store the radius of the circle, area to store the area of the circle, and circumference to store the circumference of the circle.

* We ask the user to enter the radius of the circle using printf and scanf.

* We use the #define preprocessor directive to define a constant value of PI to be used in the calculations.

* We calculate the area and circumference of the circle using the formulas area = PI * radius * radius and circumference = 2 * PI * radius.

* We print the area and circumference of the circle using printf and the %lf format specifier to print double-precision floating-point values.

* After printing the values, we return 0 to indicate successful execution of the program.