Length of Diagonal of a n | C ++ Program to find the diagonal of a regular polygon with given side length ; Function to find the diagonal of a regular polygon ; Side and side length cannot be negative ; diagonal degree converted to radians ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float polydiagonal ( float n , float a ) { if ( a < 0 && n < 0 ) return -1 ; return 2 * a * sin ( ( ( ( n - 2 ) * 180 ) / ( 2 * n ) ) * 3.14159 / 180 ) ; } int main ( ) { float a = 9 , n = 10 ; cout << polydiagonal ( n , a ) << endl ; return 0 ; }