Find the length of Kth N | C ++ program for the above approach ; Function to calculate the interior angle of a N - sided regular polygon ; Function to find the K - th polygon formed inside the ( K - 1 ) th polygon ; Stores the interior angle ; Stores the side length of K - th regular polygon ; Return the length ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define PI  3.14159265 NEW_LINE double findInteriorAngle ( int n ) { return ( n - 2 ) * PI / n ; } double calculateSideLength ( double L , int N , int K ) { double angle = findInteriorAngle ( N ) ; double length = L * pow ( sin ( angle / 2 ) , ( K - 1 ) ) ; return length ; } int main ( ) { double N = 5 , L = 21 , K = 7 ; cout << calculateSideLength ( L , N , K ) ; return 0 ; }