In this article, we are going to learn about a simple C program, in which we need to calculate the circumference of a Circle. The task is actually very easy, just you need to know how to calculate the circumference of a circle and some information about the syntax of C programs, and you can easily perform the program.
C Program To Calculate Circumference of Circle
Here is the formula for calculating the circumference of a circle –
C = 2 * pi * r
Here, C is the circumference, pi is the constant pi(approximately 3.14), and r is the radius of the circle. In the given video, you can find a detailed explanation of how you can write a C program to calculate the circumference of a circle.
Here is the C program, to calculate the circumference of a circle –
#include <stdio.h>
int main() {
double radius, circumference;
const double PI = 3.14159265359;
// Asking the user for radius of circle
printf(“Enter the radius of the circle: “);
scanf(“%lf”, &radius);
// Calculate the circumference
circumference = 2 * PI * radius;
// Displaying the result
printf(“The circumference of the circle with radius %.2lf is %.2lfn”, radius, circumference);
return 0;
}
Output –
Enter the radius of the circle: 3.5
The circumference of the circle with a radius of 3.50 is 21.99