## Problem Analysis

Circle is a geometric shape formed out of a moving point in a two dimensional plane in such a way that its distance from a given point called centre remains constant.

The constant distance between the centre and any point on the curve of the circle is called the radius. Circle occupies space on a two-dimensional plane. The space occupied by the circle is called the area of the circle.

Area of the circle can be found using the formula:

Arera = 3.14 × *r*2

Here, *r* is the radius of the circle.

## Radius of Circle

Radius is the line connecting the centre of the circle and the outer boundary of the circle. Radius of the circle is represented by *r.*

## Diameter of Circle

Diameter divides the circle into two equal parts. It is double of radius and represented by ‘d’ or ‘D’. Therefore,

D = 2R

Here, R is the radius of the circle.

Area of circle in terms of radius:

Arera = 3.14 × *r**2*

Area of circle in terms of diameter:

Area = 0.785 × d2

Area of circle in terms of circumference, ‘C’

Arera = C2 / 12.56

## Problem Description

C program to find the area of a circle can be developed in three ways:

- By using radius of circle
- By using diameter of circle
- By using circumference of circle

Input for radius, diameter and circumference of the circle is taken from the user. User input is fed into a formula defined in the problem analysis section.

## Solution to the Problem

#include <stdio.h> int main() { float pie = 3.14; float r, a; printf("Enter the radius of circle "); scanf("%f", &r); a = 3.14 * (r * r); printf("The Area of circle is %f ", a); return 0; }

Output: Enter the radius of circle 21.34 The Area of circle is 1429.942139

Code Analysis In the above code input is taken from the user in the user defined variable r. This is done by:

printf("Enter the radius of circle "); scanf("%f", &r);

Area is calculated by using the formula:

a = 3.14 * (r * r);

Area is displayed to the user by this code:

printf("The Area of circle is %f ", a);

### C program to find area of circle using diameter

#include <stdio.h> int main() { float pie = 3.14; float d, a; printf("Enter the diameter of the circle "); scanf("%f", &d); a = 0.785 * d * d; printf("The Area of circle is %f ", a); return 0; }

Output: Enter the diameter of the circle 12.23 The Area of circle is 117.414719

Output: Code Analysis In the above code input is taken from the user in the user defined variable d. This is done by:

printf("Enter the radius of circle "); scanf("%f", &d);

Area is calculated by using the formula:

a = 3.14 * (d * d);

Area is displayed to the user by this code:

printf("The Area of circle is %f ", a);

## C program to find area of Circle using Circumference

#include <stdio.h> int main() { float pie = 3.14; float c, a; printf("Enter the circumference of the circle "); scanf("%f", &c); a = (c*c)/12.56; printf("The Area of circle is %f ", a); return 0; }

Output: Enter the circumference of the circle 12.23 The Area of circle is 11.908669

Code Analysis In the above code input is taken from the user in the user defined variable c. This is done by:

printf("Enter the radius of circle "); scanf("%f", &d);

Area is calculated by using the formula:

a = (d * d) / 12.56;

Area is displayed to the user by this code:

printf("The Area of circle is %f ", a);

## C program to find area of Circle using inbuilt function

#include <stdio.h> #include<math.h> int main(void) { float r, a; printf("Input radius of the circle \n"); scanf("%f", &r); a = (float)(3.14* (pow(r,2))); printf("The circle area is %f", a); return 0; }

Output: Input radius of the circle is 12.23 The circle area is 469.658875

Code Analysis In the above code input is taken from the user in the user defined variable r. This is done by:

printf("Enter the radius of circle "); scanf("%f", &r);

Area is calculated by using the formula:

a = (float)(3.14* (pow(r,2)));

Area is displayed to the user by this code:

printf("The circle area is %f ", a);

## C program to find area of circle using pointers and functions

#include <stdio.h> void area_of_circle(float *v, float * res); int main() { float r, a; printf("\n Input radius of Circle :"); scanf("%f", &r); area_of_circle(&r, &a); printf("The area of circle is : %f", a); return 0; } void area_of_circle(float *v, float *res) { *res = 3.14 * (*v) * (*v); }

Output: Input radius of Circle :23.34 The area of circle is : 1710.532593

Output: Code Analysis In this code area of the circle is calculated using function and pointers. User input is taken in the user-defined variable r. This is done by following programming instructions:

printf("\n Input radius of Circle :"); scanf("%f", &r);

Area is calculated by passing the value of r to a function whose argument is of type pointer. The function prototype is:

void area_of_circle(float *v, float * res);

Pointer v takes the address of the variable r, r has radius value. Variable ‘a’ is used to hold and display the area of a circle, its address is passed to the function. Address of variable ‘a’ is hold by pointer variable *res. Area of circle is calculated by executing the following programming instruction:

*res = 3.14 * (*v) * (*v);

As the final result is stored in a pointer variable its value is accessible in the main ( ) function and displayed to the user by executing following instructions.

printf("The area of circle is : %f", a);

**Conclusion**

The objective was to develop a C program to calculate the area of the circle. The desired objective is achieved by developing a C program to find the area of the circle.

Area of the circle can be calculated if we know the radius of the circle or if we know the diameter of the circle or if we know the circumference of the circle. The formula to calculate the area of the circle is given in the problem description section.

Program to find the area is given in the section solution to the problem.

## Leave a Reply