C Program to find area of a circle with given radius

For a better understanding of this C program example, we always recommend you to learn the basic topics of C programming listed below:

How to find the area of a circle

In this C program, we need to find the area of a circle with the radius given. A circle is a shape that has no corners, the area of a circle is calculated using the formula, pi*r**2, where, r is the radius. The radius of a circle means half of the diameter.
Let's take an example of a circle with a diameter of 4. which means the circle has a 4 cm length between the longest points. then the radius will be 2. then the area of that circle will be "pi * 2**2" which is "pi * 4" which will be 12.5.

How we calculate the area of the circle using the C program

Let's check how we implement the above logic in the C program. Import the Header files like 'stdio','conio', and 'math.h' to use the built-in function defined inside that Header Libraries. We are defining the value of 'pi' and we start the main program by accepting the value of radius from the user and save that value in a variable using Float data type, then we apply the formula 'pi * r **2' and we print the Result as an area of the circle using Printf statement.

ALGORITHM

STEP 1: Import the header file libraries into the C program to use built-in functions such as stdio, conio, and math.h.

STEP 2: Define the value of 'pi' as '3.14' using C programming syntax.

STEP 3: Open the main() to start the program in the C language.

STEP 4: After initializing the variables for radius and area using float data type, accept the value of radius from the user using printf and scanf functions in C.

STEP 5: Calculate the area of the circle using the formula 'pi * r**2'.

STEP 6: Print the result using printf statement, Here we use 5.2f which adds Precision in the float data type. which means it prints only that much decimal value as result.

C Source Code

                                          #include <stdio.h>
#include <math.h>
#define PI 3.142

void main()
{
     float radius, area;
     printf("Enter the radius of a circle\n");
     scanf ("%f", & radius);
     area = PI * pow (radius,2);
     printf ("Area of a circle = %5.2f\n", area);       
}
                                      

OUTPUT

RUN 1
=======
Enter the radius of a circle
3.2
Area of a circle = 32.17

RUN 2
========
Enter the radius of a circle
6
Area of a circle = 113.11