Area of Circle in C – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sun, 14 Aug 2022 07:55:25 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg Area of Circle in C – Programmerbay https://programmerbay.com 32 32 Program to Find Diameter, Circumference and Area of Circle in C https://programmerbay.com/c-program-to-find-area-circumference-of-a-circle/ https://programmerbay.com/c-program-to-find-area-circumference-of-a-circle/#respond Fri, 05 Aug 2022 07:19:51 +0000 https://programmerbay.com/?p=5360 The program calculates diameter, circumference, and area of a circle by simply using formula. The explanation is given below.

A circle can be defined as a collection of points that are equidistant from each other. One can calculate its area and circumference using radius or diameter.

Formula to Calculate Diameter, Circumference, and Area of a circle 

Circle

Diameter = Line that goes through the center and touches boundary as initial and end points.

Radius = Diameter/2

Area of Circle = π * r 2

Circumference of Circle = 2*π *r

 

Example 1. Program to Find Diameter, Circumference and Area of Circle in C

In the below code, we have declared a macro named pi and used it for circumference and area calculation.

Program:

#include<stdio.h>
#define pi 3.14159
int main()
{
float radius, diameter, area, crcmfrnce;
printf("Please enter the radius of the Circle = ");
scanf("%f",&radius);
diameter = 2 * radius;
crcmfrnce = 2*pi*radius;
area  = pi*radius*radius;
printf("\n\t Diameter of the circle = %.1fm \n\t Circumference of the circle = %.2fm \n\t  Area of the circle = %.2fsq.m\n",diameter,crcmfrnce,area);
return 0;
}

Output:

Please enter the radius of the Circle = 3

         Diameter of the circle = 6.0m 
         Circumference of the circle = 18.85m 
         Area of the circle = 28.27sq.m


Explanation:

  1. Getting input as a radius  from a user
  2. Then, applying formula π r 2 for area and  2π r for circumference on it , that would give area and circumference
  3. Lastly, printing the output on to the screen

Example 2. Program to Find Diameter, Circumference and Area of Circle in C  Using Math.h library.

Math.h header file consists various predefined mathematical functions. In this case, we have used its M_PI constant and pow() method to calculate circumference and area of a circle.

Program: 

#include<stdio.h>
#include<math.h>
int main()
{
float radius, diameter, area, crcmfrnce;
printf("Please enter the radius of the Circle = ");
scanf("%f",&radius);
diameter = 2 * radius;
crcmfrnce = 2*M_PI*radius;
area  = M_PI * pow(radius,2);
printf("\n\t Diameter of the circle = %.1fm \n\t Circumference of the circle = %.2fm \n\t  Area of the circle = %.2fsq.m\n",diameter,crcmfrnce,area);
return 0;
}

Output: 

Please enter the radius of the Circle = 2

   Diameter of the circle = 4.0m 
   Circumference of the circle = 12.57m 
    Area of the circle = 12.57sq.m

 

]]>
https://programmerbay.com/c-program-to-find-area-circumference-of-a-circle/feed/ 0