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 :
#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;
}
Enter the radius of the circle: 25
Area of the circle: 1963.50
Circumference of the circle: 157.08
radius
of the circle, area
to store the area of the circle, and circumference
to store the circumference of the circle.printf
and scanf
.#define
preprocessor directive to define a constant value of PI
to be used in the calculations. area = PI * radius * radius
and circumference = 2 * PI * radius
.printf
and the %lf
format specifier to print double-precision floating-point values.