Beginners Programs :

C Program Area Of Rectangle | C Programs

C Program to find the area of a rectangle – In this particular article, we will discuss how to calculate the area of a rectangle in C Programming. The methods used in this specific article are as follows:

  • Using Standard Method
  • Using Function
  • Using Pointers
  • Using Macros

As we all know, rectangles are extremely commonly used quadrilaterals. In a rectangle, the opposite sides are equal and parallel. Essentially, every square is a rectangle since its opposite sides are equal and parallel as well.

The area of a rectangle can be calculated as:

Area = Length * Breadth

A rectangle looks like this:

Rectangle

As you can see, the area of this very rectangle can be calculated very easily. The area of this rectangle is:

Area = 9 * 4 = 36 sq. units.

Thus, the different methods with which the area of a rectangle can be calculated in C programming are as follows:

Using Standard Method

1)We declared the variables length,breadth,area.

2)By substituting the values into the formula area=(length*breadth), we will get the value of area which is assigned to the variable “area”.

output:

Using Function

1)We are using the function area(float l, float b) to calculate the area of a rectangle.

2)Using the code area(l,b) we are calling the function. here area(l,b) is calling function.

3)The called function area(float l, float b) will calculate the area and return the value, that return value will be assigned to the variable “a”.

output:

Using Pointers

1)We are passing the references as arguments using the calling function area(&l,&b,&a).

2)The called function area(float *l, float *b, float *area) will calculate the area of a rectangle, which is having pointer variables as arguments.

3)The calculated value will store into the pointer variable “area”.

output:
Using Macros

1)area(l,b) is symbolic name to the expression (l*b).

2)In the code area(l,b) replaced with that expression given at #define.

output:

Leave a Reply

Your email address will not be published. Required fields are marked *

*