How to write a C Program to find the Diameter, Circumference, and Area Of a Circle using Functions with examples? The mathematical formulas behind these calculations are:
- Diameter of a Circle = 2r = 2 * radius
- Circumference of a Circle = 2πr = 2 * π * radius
- Area of a circle is: A = πr² = π * radius * radius
C Program to find Diameter, Circumference, and Area Of a Circle
This program allows the user to enter the radius of a circle. Using that radius value, this program will find the Diameter, Circumference, and Area Of a Circle
TIP: Please refer Program to Calculate Area article to understand the various Programming ways to calculate the same.
#include<stdio.h>
#define PI 3.14
int main()
{
float radius, area, circumference, diameter;
printf("\n Please Enter the radius of a circle : ");
scanf("%f",&radius);
diameter = 2 * radius;
circumference = 2 * PI * radius;
area = PI * radius * radius;
printf("\n Diameter Of a Circle = %.2f\n", diameter);
printf("\n Circumference Of a Circle = %.2f\n", circumference);
printf("\n Area Of a Circle = %.2f\n", area);
return 0;
}

C Program to find Diameter, Circumference, and Area Of a Circle using Functions
In this program, we are using Functions that find the Diameter, Circumference, and Area Of a Circle. Remember, you have to include math.h library to use M_PI. Otherwise, manually define the PI value as we did in the first example.
#include<stdio.h>
#include<math.h>
double find_Diameter(double radius);
double find_Circumference(double radius);
double find_Area(double radius);
int main()
{
float radius, area, circumference, diameter;
printf("\n Please Enter the radius of a circle : ");
scanf("%f",&radius);
diameter = find_Diameter(radius);
circumference = find_Circumference(radius);
area = find_Area(radius);
printf("\n Diameter Of a Circle = %.2f\n", diameter);
printf(" Circumference Of a Circle = %.2f\n", circumference);
printf(" Area Of a Circle = %.2f\n", area);
return 0;
}
double find_Diameter(double radius)
{
return 2 * radius;
}
double find_Circumference(double radius)
{
return 2* M_PI * radius;
}
double find_Area(double radius)
{
return M_PI * radius * radius;
}
From the above code snippet, you can see we created three functions.
- double find_Diameter(double radius) function to calculate the Diameter of a circle.
- double find_Circumference(double radius) function to calculate the Circumference of a circle.
- And double find_Area(double radius) function to find the Area of a circle.
- Next, we called those functions in the main() program to calculate those values.
When the compiler reaches the above-specified functions in the main() program, the compiler will immediately jump to their respective function definitions.
Please Enter the radius of a circle : 10
Diameter Of a Circle = 20.00
Circumference Of a Circle = 62.83
Area Of a Circle = 314.16
Comments are closed.