The circumference of a figure is the sum of all the side lengths. To calculate the circumference of square, length of one of the side is required as all sides are equal. To calculate the circumference of rectangle, length and breadth of rectangle is required.
Circumference of a Square:

The circumference of a square is given by the formula:
C = 4 * a where a is the side length.
Examples :
input: 4 output: 16 input: 3 output: 12
C++
// CPP program to find // Circumference of a square #include <bits/stdc++.h> using namespace std; int Circumference(int a) { return 4 * a; } // Driver Code int main() { int a = 5; cout << "Circumference of" <<" a square is " << Circumference(a); return 0; } // This code is contributed // by mohitw16 |
Java
// Java program to find // Circumference of a square import java.io.*; class GFG { int Circumference(int a) { return 4 * a; } // Driver code public static void main(String args[]) { GFG obj = new GFG(); int a = 5; System.out.println("Circumference of " + "a square is " + obj.Circumference(a)); } } // This code is contributed // by Anshika Goyal. |
Python3
# Python3 Program to find # Circumference of a square def Circumference(a): return (4 * a) # Driver code a = 5c = Circumference(a) print("Circumference of a " + "square is % d" % (c)) |
C#
// C# program to find Circumference // of a square using System; class GFG { static int Circumference(int a) { return 4 * a; } // Driver Code public static void Main() { int a = 5; Console.WriteLine("Circumference" + " of a square is " + Circumference(a)); } } // This code is contributed by vt_m. |
PHP
<?php // PHP program to find // Circumference of a square function Circumference($a) { return 4 * $a; } // Driver Code $a = 5; echo "Circumference of a ". "square is ", Circumference($a); // This code is contributed by ajit ?> |
Output :
Circumference Of a square is 20
Circumference of a rectangle:

The circumference of a rectangle is given by the formula:
C = 2 * (l + W) where l is the length and W is the width.
Examples :
input: 2 4 output: 12 input: 4 6 output: 20
C++
// C++ Program to find // Circumference of a rectangle #include <iostream> using namespace std; int Circumference(int l, int w) { return (2 * (l + w)); } // Driver code int main() { int l = 8, w = 4; int c = Circumference(l, w); cout << "Circumference of a" << " rectangle is " << c << endl; return 0; } // This code is contributed by vt_m. |
Python3
# Python Program to find # Circumference of a rectangle def Circumference(l, w): return (2 * (l + w)) # Driver code l = 8w = 4c = Circumference(l, w) print("Circumference of a" + " rectangle is % d" % (c)) |
Java
// java Program to find // Circumference of a rectangle import java.io.*; class GFG { static int Circumference(int l, int w) { return (2 * (l + w)); } // Driver code static public void main(String[] args) { int l = 8, w = 4; int c = Circumference(l, w); System.out.println("Circumference of " + "a rectangle is " + c); } } // This code is contributed by vt_m. |
C#
// C# Program to find // circumference of a rectangle using System; class GFG { static int Circumference(int l, int w) { return (2 * (l + w)); } // Driver code static public void Main() { int l = 8, w = 4; int c = Circumference(l, w); Console.WriteLine("Circumference of " + "a rectangle is " + c); } } // This code is contributed by vt_m. |
PHP
<?php // Php Program to find // Circumference of a rectangle function Circumference($l,$w) { return (2 * ($l + $w)); } // Driver code $l = 8; $w = 4; $c = Circumference($l, $w); echo "Circumference of a ". "rectangle is " ,$c ,"\n"; // This code is contributed by aj_36. ?> |
Output :
Circumference of a rectangle is 24
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Program for Area And Perimeter Of Rectangle
- Area and Perimeter of Rectangle in PL/SQL
- Program to find Circumference of a Circle
- Maximum area of rectangle possible with given perimeter
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Program for Circumference of a Parallelogram
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given
- Area of a Square | Using Side, Diagonal and Perimeter
- Minimum Cost Path to visit all nodes situated at the Circumference of Circular Road
- Number of quadrilateral formed with N distinct points on circumference of Circle
- Maximum perimeter of a square in a 2D grid
- Ratio of area of a rectangle with the rectangle inscribed in it
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Program to find the Area and Perimeter of a Semicircle
- Program to print hollow rectangle or square star patterns
- C Program for Find the perimeter of a cylinder
- Java Program for Find the perimeter of a cylinder
- Python Program for Find the perimeter of a cylinder
- Program to find the Perimeter of a Regular Polygon
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

