Write a C program to find the area of a circle using the given radius.

**Area of circle** is defined as **pi*r*r** where **pi** is a constant whose value is (22/7 or 3.142) and **r** is the radius of a circle.

Formula to calculate the area of circle is: **Area = pi*r*r**

**Example:**

If the radius of a circle is **30**, then area of circle is **pi*r*r** = 3.14*30*30 = 2827.80.

Step 1: Start the program

Step 2: Input the value of radius (float value).

Step 3: Calculate area using formula **pi*(r ^{2})**

Step 4: Print area of circle

Step 5: End the Program

For a better understanding of the Area of circle program, consider the following two scenarios.

In this approach, we calculate the area of a circle using the given radius and print the result as a float.

**Examples:**

If the radius of a circle is 10, then its area would be 3.141592*10*10 = 314.16 approx.

If the radius is 11.1,then the area of the circle would be 3.141592*11.1*11.1 = 387.08 approx.

Here is source code of the C program to calculate the area of a circle. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

#include <stdio.h> //Defining the value of pi upto 6 decimal places #define pi 3.141592 int main() { float radius; printf("Enter Radius of Circle:\n"); scanf("%f",&radius); float area=pi*radius*radius; //Precision of the radius and area in this program is upto two decimal places printf("The area of Circle with radius %0.2f is: %0.2f",radius,area); return 0; }

First, Input the **radius** which is a float value. Then calculate its area using **pi*r*r** and print the area upto desired precision. (In the above program the precision is of 2 decimal places, for which we have used **%0.2f**. For 5 decimal places use **%0.5f**)

**Time Complexity: O(1)**

In the above program there are no iterative statements,no function calls, the only operation performed is input output, so time complexity is O(1)

**Space Complexity: O(1)**

Since no auxiliary space is required, space complexity is O(1).

**Testcase 1:** Here, the given radius is “10”

Enter Radius of Circle: 10 The area of Circle with radius 10 is: 314.16

**Testcase 2:** Here, the given radius is “11.1”

Enter Radius of Circle: 11.1 The area of Circle with radius 11.1 is: 387.08

In this approach, we calculate the area of a circle using the pow function and print the result as a float.

**Examples:**

If the radius of a circle is 20, then its area would be 3.142*15*15 = 706.95 approx.

Here is source code of the C program to calculate the area of a circle using function. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/* * C program to find the area of a circle, given the radius */ #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); }

In this C program, library function defined in <math.h> header file is used to compute mathematical functions. We are reading the radius of a circle using ‘radius’ variable. To find the area of a circle, the following formula is used.

**Area = PI * pow (radius, 2)**

**Time Complexity: O(1)**

In the above program there are no iterative statements, so time complexity is O(1).

**Space Complexity: O(1)**

Since no auxiliary space is required, space complexity is O(1).

Enter the radius of a circle 15 Area of a circle = 706.95

To practice programs on every topic in C, please visit “Programming Examples in C”, “Data Structures in C” and “Algorithms in C”.

**Next Steps:**

- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

**Related Posts:**

- Apply for Computer Science Internship
- Buy Computer Science Books
- Apply for C Internship
- Buy C Books
- Practice BCA MCQs