C Program to Find Area of Circle
![C++ Course: Learn the Essentials](https://www.scaler.com/topics/images/instructor-prateek.webp)
In school, we often enjoyed calculating the areas of various shapes such as rectangles, triangles, and circles. However, these calculations can become complex when dealing with large numbers or decimals. To simplify, let’s develop a program in C to calculate the area of a circle. In this article, we'll explore how to use the area formula effectively within a C program, focusing specifically on circles.
Algorithm for C Program to Find Area of Circle
Here is an algorithm for a C program to find the area of a circle:
- Declare variables for the radius and the area of the circle.
- Prompt the user to enter the radius of the circle.
- Read the user input and store it in the radius variable.
- Calculate the area of the circle using the formula area = pi * radius * radius.
- Print the area of the circle to the console.
C Program to Calculate Area of a Circle Using Radius
In this method, we will be calculating the area of a circle using its radius.
As we know, the formula to find the area of a circle, if the radius is given is -
Now simply, we have to write a program to convert this logic into code, so let's begin,
Writing Area of circle program in C
Input
Output
Explanation
In the above program, first, we initialize the variable pi with the value of π and take input for radius then using the formula pi*radis*radis calculated the area of the circle.
Complexity Analysis
- Time Complexity: O(1). This is because the program only performs simple arithmetic operations, which are all constant time operations.
- Space Complexity: O(1). This is because the program only uses a few variables, which do not grow in size with the input size.
C Program to Calculate the Area of a Circle Using Circumference
In this method, we will be given the circumference of a circle, and using that we have to find its area.
We will again apply the same thing, we know the formula, and all we have to do is write a program using that logic. If we have the circumference of a circle, then we can find its area using the formula
Writing Area of circle program in C
Input
Output
Explanation
In the above program, first, we initialize the variable pi with the value of π and take input for circumference then using the formula calculated the area of the circle.
Complexity Analysis
- Time Complexity: O(1). This is because the program only performs simple arithmetic operations, which are all constant time operations.
- Space Complexity: O(1). This is because the program only uses a few variables, which do not grow in size with the input size.
Conclusion
- The area of a shape is the measurement of how much space it is covering if kept on a plane.
- Area of a circle if the radius is given
- Area of a circle if the circumference is given
- Now, we are aware of all the above formulas, so all we have to do is to think about the logic that how to implement these mathematical formulae into a program, and then find the area we need.