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