⓯ Program to Find the Area of a Circle in C (with complete explanation)
๐ข Program to Find the Area of a Circle in C
๐ Problem Statement
Write a C program to calculate the area of a circle when the radius is given by the user.
๐ Theory
The area of a circle is calculated using the formula:
Where:
-
ฯ (pi) ≈ 3.14159
-
r = radius of the circle
Since the result may be a decimal value, we use the float data type.
๐ง Algorithm
-
Start
-
Declare variables
radiusandarea -
Read the value of radius from the user
-
Calculate area using the formula
-
Display the result
-
End
๐ป C Program
๐ Explanation of the Code
-
#include <stdio.h>
→ Includes standard input-output functions. -
float radius, area;
→ Used to store decimal values. -
const float PI = 3.14159;
→ Constant value of ฯ. -
scanf("%f", &radius);
→ Takes radius as input from the user. -
area = PI * radius * radius;
→ Formula to calculate the area. -
printf("Area of the circle = %.2f", area);
→ Displays the area up to 2 decimal places.
▶️ Sample Output
Input
Output
✅ Conclusion
This program efficiently calculates the area of a circle using a simple mathematical formula. It is beginner-friendly and commonly asked in C programming interviews and exams.
Comments
Post a Comment