C program to find area of circle

Simple-C-Program

In this article, we are going to learn how to find the area of a circle using a C program. We will use the maths formula for the calculation of the area of a circle. This will include the pi constant also. so let us begin with our first program.

C Program to find area of circle


The formula to calculate the area of a circle is ℼ*r2. In this formula, we have pi as constant and r is the radius of the circle. r is raised to the power of 2. In our code, we are using a 3.14 value. This is the constant value of pi. Let us see now how to write this using C code.

#include<stdio.h>
int main()
{     
     float radius, area;

     printf("Please enter Radius of Circle: ");
     scanf("%f", &radius);

     
     area = 3.14 * radius * radius;
 
     printf("The Area of the Circle is = %.2f \n",radius,area);

     return 0;
}

Output

Please enter Radius of Circle: 14
The Area of the Circle is = 14.00 

C program to find area of circle using macro


We can make use of the #define macro for PI. This can be done by just declaring a macro in your code. Macros can be defined as a constant value that you desire to use in your code.

#include<stdio.h>
#define PI 3.14
int main()
{     
     float radius, area;

     printf("Please enter Radius of Circle: ");
     scanf("%f", &radius);

     
     area = PI * radius * radius;
 
     printf("The Area of the Circle is = %.2f \n",radius,area);

     return 0;
}

Output

Please enter Radius of Circle: 12
The Area of the Circle is = 12.00