how to find the perimeter of a polygon
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:
Attention reader! Don't stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course .
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++
#include <iostream>
using
namespace
std;
float
Perimeter(
float
s,
int
n)
{
float
perimeter = 1;
perimeter = n * s;
return
perimeter;
}
int
main()
{
int
n = 5;
float
s = 2.5, peri;
peri = Perimeter(s, n);
cout <<
"Perimeter of Regular Polygon"
<<
" with "
<< n <<
" sides of length "
<< s <<
" = "
<< peri << endl;
return
0;
}
C
#include <stdio.h>
float
Perimeter(
float
s,
int
n)
{
float
perimeter = 1;
perimeter = n * s;
return
perimeter;
}
int
main()
{
int
n = 5;
float
s = 2.5, peri;
peri = Perimeter(s, n);
printf
(
"Perimeter of Regular Polygon\n"
" with %d sides of length %f = %f\n"
,
n, s, peri);
return
0;
}
Java
class
GFG {
static
double
Perimeter(
double
s,
int
n)
{
double
perimeter =
1
;
perimeter = n * s;
return
perimeter;
}
public
static
void
main(String[] args)
{
int
n =
5
;
double
s =
2.5
, peri;
peri = Perimeter(s, n);
System.out.println(
"Perimeter of Regular Polygon"
+
" with "
+ n +
" sides of length "
+ s +
" = "
+ peri);
}
}
Python3
def
Perimeter(s, n):
perimeter
=
1
perimeter
=
n
*
s
return
perimeter
if
__name__
=
=
'__main__'
:
n
=
5
s
=
2.5
peri
=
Perimeter(s, n)
print
(
"Perimeter of Regular Polygon with"
,n,
"sides of length"
,s,
"="
,peri)
C#
using
System;
class
GFG
{
static
double
Perimeter(
double
s,
int
n)
{
double
perimeter = 1;
perimeter = n * s;
return
perimeter;
}
static
public
void
Main ()
{
int
n = 5;
double
s = 2.5, peri;
peri = Perimeter(s, n);
Console.WriteLine(
"Perimeter of Regular Polygon"
+
" with "
+ n +
" sides of length "
+
s +
" = "
+ peri);
}
}
PHP
<?php
function
Perimeter(
$s
,
$n
)
{
$perimeter
= 1;
$perimeter
=
$n
*
$s
;
return
$perimeter
;
}
$n
= 5;
$s
= 2.5;
$peri
= Perimeter(
$s
,
$n
);
echo
"Perimeter of Regular Polygon"
,
" with "
,
$n
,
" sides of length "
,
$s
,
" = "
,
$peri
;
?>
Javascript
<script>
function
Perimeter(s, n)
{
var
perimeter = 1;
perimeter = n * s;
return
perimeter;
}
var
n = 5;
var
s = 2.5, peri;
peri = Perimeter(s, n);
document.write(
"Perimeter of Regular Polygon<br/>"
+
" with "
+ n +
" sides of length "
+
s.toFixed(6) +
" = "
+ peri.toFixed(6));
</script>
Output:
Perimeter of Regular Polygon with 5 sides of length 2.500000 = 12.500000
how to find the perimeter of a polygon
Source: https://www.geeksforgeeks.org/program-to-find-the-perimeter-of-a-regular-polygon/
Posted by: watkinsposiciente.blogspot.com
0 Response to "how to find the perimeter of a polygon"
Post a Comment