⓯ 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:

Area=ฯ€×r×r

Where:

  • ฯ€ (pi)3.14159

  • r = radius of the circle

Since the result may be a decimal value, we use the float data type.


๐Ÿง  Algorithm

  1. Start

  2. Declare variables radius and area

  3. Read the value of radius from the user

  4. Calculate area using the formula

  5. Display the result

  6. End


๐Ÿ’ป C Program

#include <stdio.h> int main() { float radius, area; const float PI = 3.14159; // Taking input from user printf("Enter the radius of the circle: "); scanf("%f", &radius); // Calculating area area = PI * radius * radius; // Displaying result printf("Area of the circle = %.2f", area); return 0; }

๐Ÿ” 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

Enter the radius of the circle: 7

Output

Area of the circle = 153.94

✅ 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.


๐Ÿ“˜ C Programming Series – What’s Next?

๐Ÿ‘‰ In the next post of this series, we will learn how to print multiplication table of a number with complete explanation and output examples. Stay tuned! ๐Ÿš€

Comments

Popular posts from this blog

⓮C Program to calculate Simple Interest (With Program and Explanation)

⑫ C Program to Swap Two Numbers Without Using a Temporary Variable (With Program and Explanation)

9️⃣C Program to Find LCM of Two Numbers (With Program and Explanation)