In this tutorial you will learn about the C Program to Find Diameter, Circumference, and Area of a Circle and its application with practical example.
C Program to Find Diameter, Circumference, and Area of a Circle
In this tutorial, we will learn to create a C program that will Find the Diameter, Circumference, and Area of a Circle in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Mathematical operations in C programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input radius from the user of the circle. 3. <strong>C</strong><strong>alculating the Diameter, Circumference, and Area of a Circle</strong> using the code. 4. Printing the results from the program. 5. End the program. |
Program description:-
In today’s tutorial, we will create a program, that will calculate the Diameter, Circumference, and Area of a Circle using C programming. First, take the input radius of the circle from the user. Then we will calculate the Diameter, Circumference, and Area of a Circle using the mathematical expressions in the c programming language. At last, we will print the Diameter, Circumference, and Area of a Circle.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
/* C Program to find Diameter, circumference, and Area Of a Circle */ //including the header files of the program. #include<stdio.h> #include<math.h> //defining the functions for the calculations. double dmc(double rad);//function for finding the Diameter of circle double cmc(double rad);//function for the circumference of circle double amc(double rad);//function for finding the Area of circle int main() { //declaring the required variables for the program. float rad, ar, cm, dm; //taking the input from the user printf("\n Please Enter the radius of a circle : "); //Scanning the input value from the console scanf("%f",&rad); //Calling the function for finding the Diameter of circle dm = dmc(rad); //calling the function for the circumference of circle cm = cmc(rad); //calling the function for finding the Area of circle ar = amc(rad); //Printing the output of the Diameter of the circle printf("\n Diameter Of a Circle = %.2f\n", dm); //Printing the output of the Circumference of the circle printf(" Circumference Of a Circle = %.2f\n", cm); //Printing the output of the area of the circle printf(" Area Of a Circle = %.2f\n", ar); return 0; } //bodies of the user defined functions double dmc(double rad) { return 2 * rad; } double cmc(double rad) { return 2* M_PI * rad; } double amc(double rad) { return M_PI * rad * rad; } |
Output:-
In the above program, we have first initialized the required variable.
- rad = it will hold the integer value for the input radius of the circle.
- ar = it will hold the value of the area of the circle.
- cm = it will hold the value of the area of the circle.
- dm = it will hold the value of the area of the circle.
Taking Input the radius of the circle from the user.
Defining the functions for the program.
Calling the user-defined functions.
Body of the user-defined functions for the calculations.
Printing the Diameter, Circumference, and Area of a Circle.