Table of Contents
ToggleIn this blog post, we will checkout the area of circle program in C programming. The area of a circle is given by the formula ( πr^2 ), where ( r ) is the radius of the circle and (π) (Pi) is a constant approximately equal to 3.14159. This formula is a cornerstone in geometry and is pivotal in various applications across science and engineering fields. Our focus will be on implementing this formula in a C program to efficiently compute the area, providing a practical approach to understanding mathematical concepts through programming.
Area of Circle Formula
Area = π * Radius * Radius
Where value of pie = 3.14159 and radius will be given by the user.
How to Write Area of Circle Program in C?
To create a C program for finding the area of a circle, you can follow this algorithm and corresponding pseudo code.
Algorithm:
- Start: Begin the process.
- Input Radius: Prompt the user to input the radius of the circle.
- Calculate Area: Use the formula Area = π * Radius * Radius to calculate the area of the circle.
- Display Area: Show the calculated area to the user.
- End: Conclude the process.
Pseudo Code:
BEGIN
DECLARE radius, area AS FLOAT
PRINT "Enter the radius of the circle: "
READ radius
area = π * radius * radius
PRINT "The area of the circle with radius ", radius, " is: ", area
END
C Program to Find Area of Circle
#include <stdio.h>
int main() {
double radius, area;
// initializing the value of pi
double pi = 22.0 / 7.0;
// Prompt user and get radius
printf("Enter the radius of the circle: ");
scanf("%lf", &radius); // %lf for reading double
// Calculate area
area = pi * radius * radius; // M_PI is from math.h
// Display the area
printf("The area of the circle with radius %.2lf is: %.2lf\n", radius, area);
return 0; // End of program
}
Output
In the above program, first, we initialise the variable pi with the value of π and take input for radius then using the area of circle formula calculated the area of the circle.
Time Complexity: The time complexity of this program is O(1). This is because the calculation of the area of a circle is achieved through a straightforward arithmetic expression that does not depend on iterative or recursive processes.
Space Complexity: The space complexity is also O(1). This is because program uses few variables which doesn’t not grow with the input size.
Conclusion
- On a plane, a shape’s area is the amount of space it covers.
- When the radius is given, the area of a circle is Area=π∗(radius)2Area=π∗(radius)2
- Using the above we have discussed area of circle program in C.
If you liked this post you can checkout other C Programs.
FAQ
What is the formula of area of C?
The area of circle can be calculated given either the radius (r) , the diameter (d), using one of the following formulas: Area = πr^2 Area = (π/4) × d.
Can the same program be used to find the area of a circle with a different programming language?
Yes, the formula and logic for calculating the area of a circle remain the same across different programming languages. All you need is to just change the syntax according to programming language.
Are there any libraries or functions available in C for calculating the area of a circle?
C does not provide built-in functions for calculating the area of a circle