How to find the Area and Circumference of the Circle in C?
|In this C Programming example, we will implement the program to find the area and circumference of the circle and print the output on the console.
1. How to find the area and circumference of the circle?
Circumference of the circle is the measurement of the edge of the circle. Whereas the area of the circle represents the region occupied by it.
To determine area and circumference we need to identify the radius of the circle. So, the program will indicate the user to enter the radius. Based on the input it would determine the values.
To make it easier we have taken the standard PI value as 3.14 (constant) in the program.
1.1. What is the formula for the Area of a Circle?
Given that we know the radius the area of circle is calculated as-
A= πr2
1.2. What is the formula for the Circumference of a Circle?
Given that we know the radius the circumference of the circle is calculated as-
C = 2πr
So let’s see how it to calculate area and circumference of a circle mathematically.
Example Input: radius: 5 Output: The Area of circle is: = 3.14 * 5 * 5 = 78.500000 The Circumference of circle is: = 3.14 * 5 * 5 = 31.400002
Helpful topics to understand this program better are-
2. C Program to find the area and circumference of the circle
Let’s discuss the execution(kind of pseudocode) for the program to find the area and circumference of the circle in C.
- Initially, we ask the user to enter the radius of the circle.
- The input gets stored in the
int radius
, and the value of the PI, area, and circumference gets stored in thefloat PI = 3.14, area, circumference
respectively. - Now, we perform the calculations on the input to get the area and circumference of the circle using the specified formula.
- After the calculations, print the results on the console.
Let us now implement the above execution of the program to find the area and circumference of the circle in C.
#include <stdio.h> int main() { int radius; float PI = 3.14, area, circumference; printf("Enter the radius of circle: "); scanf("%d", &radius); area = PI * radius * radius; printf("The Area of circle is: %f", area); circumference = 2 * PI * radius; printf("\nThe Circumference of circle is: %f", circumference); return 0; }
Output Enter the radius of circle: 2 The Area of circle is: 12.560000 The Circumference of circle is: 12.560000
3. Conclusion
In this C Programming example, we have discussed how to find the area and circumference of the circle in C.
Helpful Links
Please follow C Programming tutorials or the menu in the sidebar for the complete tutorial series.
Also for the example C programs please refer to C Programming Examples.
All examples are hosted on Github.
Recommended Books
An investment in knowledge always pays the best interest. I hope you like the tutorial. Do come back for more because learning paves way for a better understanding
Do not forget to share and Subscribe.
Happy coding!! ?