The area of a rectangle is a fundamental mathematical concept frequently used in various fields. In C programming calculating the area of a rectangle is a simple yet essential task that demonstrates the basic principles of mathematical computation and variable manipulation in C.
Table of Contents
Formula for the Area Of Rectangle
The formula to calculate area of a rectangle is simple and straight forward-
Area = Length * Width
Here, Length represents the longer side of the rectangle while Width represents the shorter side of the rectangle.
C Program to Calculate Area of Rectangle
Let’s write a C program to calculate the area of a rectangle
#include <stdio.h>
void main()
{
float length, width, area;
printf("Enter the length of rectangle ");
scanf("%f", &length);
printf("Enter the width of rectangle ");
scanf("%f", &width);
area = length * width;
printf("The area og given rectangle is = %f", area);
}
Output
How the Above C Program Works?
- The program starts with the declaration of three variables-
length
,width
, andarea
of typefloat
. - Then program asks the user to input the length and width of the rectangle.
- The area of a rectangle is calculated by multiplying the
length
andwidth
. - At the end, the calculated area is printed.
Happy Coding
3 thoughts on “Calculating Area of Rectangle Using C Program”