C program to calculate area of circle


In this article, we will illustrate c program to calculate area of circle. The formula for the area of circle is :

Area_circle = Π * r * r

where,

mathematical value of Π is 3.14159.

Please go through following articles of c programming, if you do not already know about these topics :

simple c program to calculate area of circle

#include <stdio.h>
 
int main() {
   float radius, area_circle;
 
   // take radius as input
   printf("Enter the radius of circle : ");
   scanf("%f", &radius);
 
   area_circle = 3.14 * radius * radius;
   printf("Area of circle : %f", area_circle);
 
   return 0;
}

Output

Enter the radius of circle : 10.0
Area of circle : 31.4

In this program first, user is asked to enter the value of radius of the circle. After that area is calculated and then displayed.

C program for calculating area of a circle using function

#include <stdio.h>

// function definition to calculate area of circle
int areaOfcircle(int radius_circle){

   float area_circle;
   area_circle = 3.14 * radius_circle * radius_circle;

   return area_circle;
 }

int main() {
   float radius;
 
   // take radius as input
   printf("Enter the radius of circle : ");
   scanf("%f", &radius);
 
   printf("Area of circle : %f", areaOfcircle(radius));
 
   return 0;
}

Output

Enter the radius of circle : 10.0
Area of circle : 31.4

This program also calculates and display the area of the circle but only difference is a function name areaOfcirlce() is used to calculate area of circle and return it.