In this post, we will learn how to find the circumference of a circle using C Programming language.
The circumference of a circle is its boundary or the length of the complete arc of the circle.
The circumference of the circle can be calculated using the formula 2Ï€r, where ‘r‘ is the radius of the circle and Ï€ = 3.14.
We will be finding the circumference of the circle by using the following methods:
- Using Standard Method
- Using User-defined Function
So, without further ado, let’s begin this tutorial.
Contents
C Program to Find Circumference of Circle
// C Program to Find Circumference of Circle #include <stdio.h> int main(){ float radius, PI = 3.14, cf; // Asking for input printf("Enter the radius of the circle: "); scanf("%f", &radius); // Circumference cf = 2 * PI * radius; // Display output printf("Circumference of Circle: %.2f", cf); return 0; }
Output
Enter the radius of the circle: 21
Circumference of Circle: 131.88
How Does This Program Work ?
float radius, PI = 3.14, cf;
In this program, we have declared three float data type variables named radius, Pi and cf.
// Asking for input printf("Enter the radius of the circle: "); scanf("%f", &radius);
Then, the user is asked to enter the radius of the circle.
// Circumference cf = 2 * PI * radius;
We calculate the circumference of the circle using the formula 2Ï€r. The value of circumference gets stored in the cf named variable.
// Display output printf("Circumference of Circle: %.2f", cf);
Finally, the result is displayed on the screen using printf() function. Here, we have used %.2f format specifier because we want to display the result only till 2 decimal places.
C Program to Find Circumference of Circle Using Function
// C Program to Find Circumference of Circle Using Function #include <stdio.h> float circumference(int radius){ return 2 * 3.14 * radius; } int main(){ float radius, cf; // Asking for input printf("Enter the radius of the circle: "); scanf("%f", &radius); // Finding circumference cf = circumference(radius); // Displaying output printf("Circumference of the Circle: %.2f", cf); return 0; }
Output
Enter the radius of the circle: 7
Circumference of the Circle: 43.96
float circumference(int radius){ return 2 * 3.14 * radius; }
In this program, we have defined a custom function named circumference which returns the circumference of the circle.
// Finding circumference cf = circumference(radius);
Then, we call our custom function in the main function to display the circumference of the circle.
Conclusion
I hope after going through this post, you understand how to find the circumference of a circle using C Programming language.
If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to solve your query.
Also Read: