How to Write a C Program to Calculate the Area Of a Circle with an example?. Before we step into the program, Let’s see the definitions and formulas behind this.

The area of a circle is the number of square units inside the circle. The standard formula to calculate the area of a circle is A=πr².

## C Program to Calculate Area Of a Circle using Radius

If we know the radius, then we can calculate the area of a circle using the formula: A=πr² (Here, A is the area of the circle, and r is the radius).

In this C program to find the area of a circle, we allow the user to enter the radius, and We define pi as a global variable and assign the value of 3.14. Next, this program will find the area and circumference of a circle as per the formula.

#include<stdio.h> #define PI 3.14 int main() { float radius, area, circumference; printf("\n Please Enter the radius of a circle\n"); scanf("%f",&radius); area = PI*radius*radius; circumference = 2* PI*radius; printf("\n Area Of a Circle = %.2f\n", area); printf("\n Circumference Of a Circle = %.2f\n", circumference); return 0; }

## C Program to Calculate the Area Of a Circle using Circumference

The distance around the circle is called the circumference. If you know the circumference, we can calculate the area of a circle using the formula: A= C²⁄ 4π. Here, C is the circumference.

In this program, we included one more header file called <math.h>, It allows using pi without declaring it. This program allows the user to enter the value of the circumference. Then, this C Program will find the area of a circle as per the formula.

#include <stdio.h> #include <math.h> int main() { float area, circumference; printf("\n Please Enter the Circumference of a circle \n"); scanf("%f", &circumference); /* We can use M_PI instead of defining PI by adding math.h header file */ area = (circumference * circumference) /(4* M_PI); printf("\n Area Of Circle = %.2f\n", area); return 0; }

### C Program to Calculate the Area Of a Circle using Diameter

The distance across the circle passes through the center, called diameter. If we know the diameter, we can calculate the area of a circle using the formula: A=π/4*D² (D is the diameter)

#include<stdio.h> main() { float PI = 3.14; float area1, area2, diameter, radius; printf("\nPlease Enter the Diameter of a circle\n"); scanf("%f", &diameter); area1 = (PI/4)* (diameter*diameter); //diameter = 2 * radius //radius = diameter/2 radius = diameter/2; area2 = PI*radius*radius; printf("\nArea of Circle using direct formula = %.2f\n", area1); printf("\nArea of Circle Using Method 2 = %.2f\n", area2); return 0; }

This c program to find the area of a circle allows the user to insert the diameter value. Then it calculates the area of a circle as per the formula we shown above.

We also mentioned other approaches.

diameter = 2 * radius

radius = diameter/2

area = π*radius*radius

Comments are closed.