Articles

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

Share

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

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

 

This post was last modified on August 14, 2022

Sandeep Verma

Published by
Sandeep Verma
Tags: Area of Circle in C C c program Circumference and Area of Circle in C Circumference of Circle in C Find Diameter of circle C Program to Find Diameter