Angle between 3 given vertices in a n | Function that checks whether given angle can be created using any 3 sides ; Initialize x and y ; Calculate the number of vertices between i and j , j and k ; Calculate the angle subtended at the circumference ; Angle subtended at j can be found using the fact that the sum of angles of a triangle is equal to 180 degrees ; Driver code
function calculate_angle ( n , i , j , k ) { var x , y ; if ( i < j ) x = j - i ; else x = j + n - i ; if ( j < k ) y = k - j ; else y = k + n - j ; var ang1 = ( 180 * x ) / n ; var ang2 = ( 180 * y ) / n ; var ans = 180 - ang1 - ang2 ; return ans ; } var n = 5 ; var a1 = 1 ; var a2 = 2 ; var a3 = 5 ; document . write ( parseInt ( calculate_angle ( n , a1 , a2 , a3 ) ) ) ;