Computer >> Computer tutorials >  >> Programming >> C programming

C Program for Program to find the area of a circle?


The area is a quantity that represents the extent of the figure in two dimensions. The area of a circle is the area covered by the circle in a two dimensional plane.

To find the area of a circle, the radius[r] or diameter[d](2* radius) is required.

The formula used to calculate the area is (π*r2) or {(π*d2)/4}.

Example Code

To find the area of a circle using radius.

#include <stdio.h>
int main(void) {
   float pie = 3.14;
   int radius = 6;
   printf("The radius of the circle is %d \n" , radius);
   float area = (float)(pie* radius * radius);
   printf("The area of the given circle is %f", area);
   return 0;
}

Output

The radius of the circle is 6
The area of the given circle is 113.040001

Example Code 

To find the area of a circle using radius using math.h library. It uses the pow function of the math class to find the square of the given number.

#include <stdio.h>
int main(void) {
   float pie = 3.14;
   int radius = 6;
   printf("The radius of the circle is %d \n" , radius);
   float area = (float)(pie* (pow(radius,2)));
   printf("The area of the given circle is %f", area);
   return 0;
}

Output

The radius of the circle is 6
The area of the given circle is 113.040001

Example Code 

To find the area of a circle using Diameter.

#include <stdio.h>
int main(void) {
   float pie = 3.14;
   int Diameter = 12;
   printf("The Diameter of the circle is %d \n" , Diameter);
   float area = (float)((pie* Diameter * Diameter)/4);
   printf("The area of the given circle is %f", area);
   return 0;
}

Output

The Diameter of the circle is 12
The area of the given circle is 113.040001