The Wayback Machine - https://web.archive.org/web/20240721082318/https://www.geeksforgeeks.org/c-program-to-find-area-and-perimeter-of-rectangle/
Open In App

C Program To Find Area And Perimeter of Rectangle

Last Updated : 16 Sep, 2022
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

Here, we will find the area and perimeter of rectangle using a C Program as follows:

Example: 

Input:

l = 10 
b = 10 

Output: 

area = 100 
perimeter = 40 

Explanation: 

The formula for the area of a rectangle is 

Area = length*breadth => l*b 

The formula for the perimeter of a rectangle is 

Perimeter = 2*(length + breadth) => 2*(l+b) 

Method 1: 

C




// C program to demonstrate the
// area and perimeter of rectangle
#include <stdio.h>
 
int main()
{
 
    int l = 10, b = 10;
    printf("Area of rectangle is : %d", l * b);
    printf("\nPerimeter of rectangle is : %d", 2 * (l + b));
    return 0;
}


Output

Area of rectangle is : 100
Perimeter of rectangle is : 40

Method 2: 

C




// C program to demonstrate the
// area and perimeter of rectangle
#include <stdio.h>
 
int main()
{
 
    int l = 10, b = 10;
    int A, P;
    A = l * b;
    P = 2 * (l + b);
    printf("Area of rectangle is : %d", A);
    printf("\nPerimeter of rectangle is : %d", P);
    return 0;
}


Output

Area of rectangle is : 100
Perimeter of rectangle is : 40

Method 3: Using functions 

C




// C program to demonstrate the
// area and perimeter of rectangle
// using function
#include <stdio.h>
 
int area(int a, int b)
{
    int A;
    A = a * b;
    return A;
}
int perimeter(int a, int b)
{
    int P;
    P = 2 * (a + b);
    return P;
}
 
int main()
{
 
    int l = 10, b = 10;
    printf("Area of rectangle is : %d", area(l, b));
    printf("\nPerimeter of rectangle is : %d",
           perimeter(l, b));
    return 0;
}


Output

Area of rectangle is : 100
Perimeter of rectangle is : 40


Similar Reads

Area of a Square | Using Side, Diagonal and Perimeter
Given one of the Sides S, Diagonal D, or Perimeter P of the square, the task is to find the area of the square with the given value. Examples: Input: S = 5 Output: Area of the square using side = 25 Input: D = 4 Output: Area of the square using diagonal = 8 Input: P = 32 Output: Area of the square using perimeter = 64 Finding Area of Square using i
7 min read
C Program for Find the perimeter of a cylinder
Given diameter and height, find the perimeter of a cylinder.Perimeter is the length of the outline of a two - dimensional shape. A cylinder is a three - dimensional shape. So, technically we cannot find the perimeter of a cylinder but we can find the perimeter of the cross-section of the cylinder. This can be done by creating the projection on its
2 min read
Radius of a circle having area equal to the sum of area of the circles having given radii
Given two integers r1 and r2, representing the radius of two circles, the task is to find the radius of the circle having area equal to the sum of the area of the two circles having given radii. Examples: Input:r1 = 8r2 = 6Output:10Explanation:Area of circle with radius 8 = 201.061929 Area of a circle with radius 6 = 113.097335Area of a circle with
5 min read
Program to print hollow rectangle or square star patterns
Hollow rectangle star pattern : The task is print below hollow pattern of given dimension. ******************** * * * * * * * * ******************** Explanation: Input number of rows and columns.For rows of rectangle run the outer loop from 1 to rows.for (i = 1; i &lt; = rows; i++)For column of rectangle run the inner loop from 1 to columns. for (j
4 min read
C Program for Maximum sum rectangle in a 2D matrix | DP-27
Write a C program for a given 2D array, the task is to find the maximum sum subarray in it. For example, in the following 2D array, the maximum sum subarray is highlighted with blue rectangle and sum of this subarray is 29. This problem is mainly an extension of the Largest Sum Contiguous Subarray for 1D array. Recommended: Please solve it on “PRAC
6 min read
C Program to Find Area of Circle
The area of a circle is the region enclosed by the circle's boundary. In this article, we will learn the program to find the area of a circle in C programming. The area of a circle can simply be evaluated using the formula: Area = Pi * r2 where r is the radius of the circle and the value of Pi is 3.14159265358. Algorithm to Find Area of Circle in C
1 min read
Draw Rectangle in C graphics
rectangle() is used to draw a rectangle. Coordinates of left top and right bottom corner are required to draw the rectangle. left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner. Syntax
2 min read
Program to calculate area of a Tetrahedron
A tetrahedron is simply a pyramid with a triangular base. It is a solid object with four triangular faces, three on the sides or lateral faces, one on the bottom of the base, and four vertices or corners. If the faces are all congruent equilateral triangles, then the tetrahedron is called regular. The area of the Tetrahedron can be found by using t
5 min read
C Program to Print the Program Name and All its Arguments
The command-line argument (CLA) is the parameter provided in the system upon request. Command-line conflict is an important concept in system C. It is widely used when one needs to control your system from the outside. Command-line arguments are transferred to the main () path. Argc calculates the number of arguments in the command line and argv []
2 min read
C program to find and replace a word in a File by another given word
Pre-requisite: File Handling in CGiven a file containing some text, and two strings wordToBeFind and wordToBeReplacedWith, the task is to find all occurrences of the given word 'wordToBeFind' in the file and replace them with the given word ‘wordToBeReplacedWith’. Examples: Input : File = "xxforxx xx for xx", wordToBeFind = "xx", wordToBeReplacedWi
3 min read
three90RightbarBannerImg