C program to find area of rectangle
In this post, you will learn how to write programs using the C programming language to find the area of a rectangle.
The area of a rectangle is the region covered by the rectangle in a two-dimensional plane. A rectangle is a two-dimensional shape that has four sides and four vertices. The area of a rectangle is the number of unit squares that can fit into a rectangle. If we know the width and height of a rectangle, we can easily calculate the area of a rectangle using the following formula.
Area = Width * Height
Simple C program to calculate area of rectangle
In the given C program, we have given the width and height of a rectangle. We calculate the area of the rectangle by multiplying the width and height of the rectangle.
#include <stdio.h>
int main()
{
int width=45;
int height=20;
int area=width*height;
printf("Area of the rectangle=%d",area);
}
Output of the above code:
Area of the rectangle=900
C program to calculate area of rectangle using user input
The given C program allows a user to enter the width and height of a rectangle. Next, we calculate the area as per the formula: Area = width * height.
// C Program to find Area of a Rectangle
#include <stdio.h>
int main()
{
int length, width, area;
//Input length and width of rectangle
printf("Please enter length of rectangle: ");
scanf("%d", &length);
printf("Please enter width of rectangle: ");
scanf("%d", &width);
/* Calculate area of rectangle */
area = length * width;
/* Print area of rectangle */
printf("Area of rectangle = %d", area);
return 0;
}
Output 1
Please enter length of rectangle: 45
Please enter width of rectangle: 2
Area of rectangle = 90
Output 2
Please enter length of rectangle: 23
Please enter width of rectangle: 53
Area of rectangle = 1219
C program to find area of rectangle using user-defined function
In the given C program, we have created a user-defined function areaRectangle() to calculate the area of a rectangle.
// C Program to find Area of a Rectangle using function
#include <stdio.h>
int areaRectangle(int, int);
int main()
{
int length, width, area;
//Input length and width of rectangle
printf("Enter the length : ");
scanf("%d", &length);
printf("Enter the width : ");
scanf("%d", &width);
/* Calculate area of rectangle */
area = areaRectangle(length, width);
/* Print area of rectangle */
printf("The area of the rectangle : %d", area);
return 0;
}
int areaRectangle(int l, int w)
{
return l * w;
}
Output 1
Enter the length : 92
Enter the width : 21
The area of the rectangle : 1932
Related Articles
Prime factors of a number in cArmstrong number program in c
Write a program to check leap year in c
C program to convert celsius to fahrenheit
Fibonacci series program in C using recursion
Write a program to find area of circle in C
C program to find greatest of three numbers
C program for addition of two numbers
C program to calculate compound interest
C program to find the ASCII value of a character
C program to convert Decimal to Octal
C program to convert decimal to binary
Write a C program to calculate Simple Interest
C program to check whether a number is even or odd
C program to reverse a number
C program to check palindrome number
C program to check whether an alphabet is a vowel or consonant
Program to find square root of a number in C
C program to check whether a number is positive or negative