# Program to find the Perimeter of a Regular Polygon

Given the number of sides ‘n’ and the length of side ‘s’ of a regular polygon, the task is to find out the Perimeter of this polygon.

**Examples:**

Input: n = 7, s = 10 Output: Perimeter : 70 Since the sides are 7, Hence the given polygon is Heptagon. Therefore. Perimeter = 7*10 = 70 Input: n = 5, s = 2.5 Output: Perimeter : 12.5 Since the sides are 5, Hence the given polygon is Pentagon. Therefore. Perimeter = 5*2.5 = 12.5

**Approach:** In geometry, a regular polygon is a closed figure with all sides eqial. It is a two-dimensional figure.

Perimeter of a Regular Polygon = Number of sides * Length of each side

Below is the implementation of the above approach:

## C++

`// C++ program to find the ` `// perimeter of a regular polygon ` ` ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to calculate the perimeter ` `float` `Perimeter(` `float` `s, ` `int` `n) ` `{ ` ` ` `float` `perimeter = 1; ` ` ` ` ` `// Calculate Perimeter ` ` ` `perimeter = n * s; ` ` ` ` ` `return` `perimeter; ` `} ` ` ` `// driver code ` `int` `main() ` `{ ` ` ` ` ` `// Get the number of sides ` ` ` `int` `n = 5; ` ` ` ` ` `// Get the length of side ` ` ` `float` `s = 2.5, peri; ` ` ` ` ` `// find perimeter ` ` ` `peri = Perimeter(s, n); ` ` ` ` ` `cout << ` `"Perimeter of Regular Polygon"` ` ` `<< ` `" with "` `<< n << ` `" sides of length "` ` ` `<< s << ` `" = "` `<< peri << endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## C

`// C program to find the ` `// perimeter of a regular polygon ` ` ` `#include <stdio.h> ` ` ` `// Function to calculate the perimeter ` `float` `Perimeter(` `float` `s, ` `int` `n) ` `{ ` ` ` `float` `perimeter = 1; ` ` ` ` ` `// Calculate Perimeter ` ` ` `perimeter = n * s; ` ` ` ` ` `return` `perimeter; ` `} ` ` ` `// driver code ` `int` `main() ` `{ ` ` ` ` ` `// Get the number of sides ` ` ` `int` `n = 5; ` ` ` ` ` `// Get the length of side ` ` ` `float` `s = 2.5, peri; ` ` ` ` ` `// find perimeter ` ` ` `peri = Perimeter(s, n); ` ` ` ` ` `printf` `(` `"Perimeter of Regular Polygon\n"` ` ` `" with %d sides of length %f = %f\n"` `, ` ` ` `n, s, peri); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find the ` `// perimeter of a regular polygon ` ` ` `class` `GFG { ` ` ` ` ` `// Function to calculate the perimeter ` ` ` `static` `double` `Perimeter(` `double` `s, ` `int` `n) ` ` ` `{ ` ` ` `double` `perimeter = ` `1` `; ` ` ` ` ` `// Calculate Perimeter ` ` ` `perimeter = n * s; ` ` ` ` ` `return` `perimeter; ` ` ` `} ` ` ` ` ` `// Driver method ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` ` ` `// Get the number of sides ` ` ` `int` `n = ` `5` `; ` ` ` ` ` `// Get the length of side ` ` ` `double` `s = ` `2.5` `, peri; ` ` ` ` ` `// find perimeter ` ` ` `peri = Perimeter(s, n); ` ` ` ` ` `System.out.println(` `"Perimeter of Regular Polygon"` ` ` `+ ` `" with "` `+ n + ` `" sides of length "` ` ` `+ s + ` `" = "` `+ peri); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find the ` `# perimeter of a regular polygon ` ` ` ` ` `# Function to calculate the perimeter ` `def` `Perimeter(s, n): ` ` ` `perimeter ` `=` `1` ` ` `# Calculate Perimeter ` ` ` `perimeter ` `=` `n ` `*` `s ` ` ` ` ` `return` `perimeter ` ` ` `# driver code ` `if` `__name__` `=` `=` `'__main__'` `: ` ` ` `# Get the number of sides ` ` ` `n ` `=` `5` ` ` ` ` `#Get the length of side ` ` ` `s ` `=` `2.5` ` ` `# find perimeter ` ` ` `peri ` `=` `Perimeter(s, n) ` ` ` ` ` `print` `(` `"Perimeter of Regular Polygon with"` ` ` `,n,` `"sides of length"` `,s,` `"="` `,peri) ` ` ` `# This code is contributed by ` `# SURENDRA_GANGWAR ` |

*chevron_right*

*filter_none*

## C#

// C# program to find the

// perimeter of a regular polygon

using System;

class GFG

{

// Function to calculate the perimeter

static double Perimeter(double s, int n)

{

double perimeter = 1;

// Calculate Perimeter

perimeter = n * s;

return perimeter;

}

// Driver Code

static public void Main ()

{

// Get the number of sides

int n = 5;

// Get the length of side

double s = 2.5, peri;

// find perimeter

peri = Perimeter(s, n);

Console.WriteLine(“Perimeter of Regular Polygon” +

” with ” + n + ” sides of length ” +

s + ” = ” + peri);

}

}

// This code is contributed by Sachin

## PHP

`<?php ` `// PHP program to find the ` `// perimeter of a regular polygon ` ` ` `// Function to calculate the perimeter ` `function` `Perimeter(` `$s` `, ` `$n` `) ` `{ ` ` ` `$perimeter` `= 1; ` ` ` ` ` `// Calculate Perimeter ` ` ` `$perimeter` `= ` `$n` `* ` `$s` `; ` ` ` ` ` `return` `$perimeter` `; ` `} ` ` ` ` ` `// driver code ` ` ` ` ` `// Get the number of sides ` ` ` `$n` `= 5; ` ` ` ` ` `// Get the length of side ` ` ` `$s` `= 2.5; ` ` ` ` ` `// find perimeter ` ` ` `$peri` `= Perimeter(` `$s` `, ` `$n` `); ` ` ` ` ` `echo` `"Perimeter of Regular Polygon"` ` ` `,` `" with "` `, ` `$n` `,` `" sides of length "` ` ` `,` `$s` `,` `" = "` `,` `$peri` `; ` ` ` `// This code is contributed by ANKITRAI1 ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Perimeter of Regular Polygon with 5 sides of length 2.500000 = 12.500000

## Recommended Posts:

- Program to find the Circumcircle of any regular polygon
- Program to find the Interior and Exterior Angle of a Regular Polygon
- Apothem of a n-sided regular polygon
- Area of a n-sided regular polygon with given Radius
- Length of Diagonal of a n-sided regular polygon
- Regular polygon using only 1s in a binary numbered circle
- Area of a n-sided regular polygon with given side length
- Side of a regular n-sided polygon circumscribed in a circle
- Determine the position of the third person on regular N sided polygon
- Area of largest Circle inscribe in N-sided Regular polygon
- C Program for Find the perimeter of a cylinder
- Program to find the Area and Perimeter of a Semicircle
- Python Program for Find the perimeter of a cylinder
- Java Program for Find the perimeter of a cylinder
- Program to find Perimeter / Circumference of Square and Rectangle

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.