codeparrot/xlcost-text-to-code huggingface dataset:
Sine Rule with Derivation , Example and Implementation | Function to calculate remaining two sides ; Calculate angle B ; Convert angles to their respective radians for using trigonometric functions ; Sine rule ; Print the answer ; Input ; Function Call
function findSides ( A , C , c ) { let B = 180 - ( A + C ) ; A = A * ( 3.14159 / 180 ) ; C = C * ( 3.14159 / 180 ) ; B = B * ( 3.14159 / 180 ) ; let a = ( c / Math . sin ( C ) ) * Math . sin ( A ) ; let b = ( c / Math . sin ( C ) ) * Math . sin ( B ) ; document . write ( a . toPrecision ( 4 ) + " " ) ; document . write ( b . toPrecision ( 4 ) + " " ) ; } let A = 45.0 ; let C = 35.0 ; let c = 23 ; findSides ( A , C , c ) ;
Equation of a normal to a Circle from a given point | Function to calculate the slope ; Store the coordinates the center of the circle ; If slope becomes infinity ; Stores the slope ; If slope is zero ; Return the result ; Function to find the equation of the normal to a circle from a given point ; Stores the slope of the normal ; If slope becomes infinity ; If slope is zero ; Otherwise , print the equation of the normal ; Given Input ; Function Call
function normal_slope ( a , b , x1 , y1 ) { var g = a / 2 ; var f = b / 2 ; if ( g - x1 == 0 ) return ( - 1 ) ; var slope = ( f - y1 ) / ( g - x1 ) ; if ( slope == 0 ) return ( - 2 ) ; return slope ; } function normal_equation ( a , b , x1 , y1 ) { var slope = normal_slope ( a , b , x1 , y1 ) ; if ( slope == - 1 ) { document . write ( " " + x1 ) ; } if ( slope == - 2 ) { document . write ( " " + y1 ) ; } if ( slope != - 1 && slope != - 2 ) { x1 *= - slope ; x1 += y1 ; if ( x1 > 0 ) document . write ( " " + slope + " " + x1 . toFixed ( 1 ) ) ; else document . write ( " " + slope + " " + x1 . toFixed ( 1 ) ) ; } } var a = 4 , b = 6 , c = 5 ; var x1 = 12 , y1 = 14 ; normal_equation ( a , b , x1 , y1 ) ;
Sum of squares of distances between all pairs from given points | Function to find the sum of squares of distance between all distinct pairs ; Stores final answer ; Traverse the array ; Adding the effect of this polet for all the previous x - polets ; Temporarily add the square of x - coordinate ; Add the effect of this polet for all the previous y - polets ; Prlet the desired answer ; Driver code
function findSquareSum ( Coordinates , N ) { let xq = 0 , yq = 0 ; let xs = 0 , ys = 0 ; let res = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let a , b ; a = Coordinates [ i ] [ 0 ] ; b = Coordinates [ i ] [ 1 ] ; res += xq ; res -= 2 * xs * a ; res += i * ( a * a ) ; xq += a * a ; xs += a ; res += yq ; res -= 2 * ys * b ; res += i * b * b ; yq += b * b ; ys += b ; } document . write ( res ) ; } let arr = [ [ 1 , 1 ] , [ - 1 , - 1 ] , [ 1 , - 1 ] , [ - 1 , 1 ] ] ; let N = arr . length ; findSquareSum ( arr , N ) ;
Count points from an array that lies inside a semi | Javascript program for above approach ; Traverse the array ; Stores if a point lies above the diameter or not ; Stores if the R is less than or equal to the distance between center and point ; Driver code
function getPointsIns ( x1 , y1 , radius , x2 , y2 , points ) { let ans = 0 ; for ( let i = 0 ; i < points . length ; i ++ ) { let condOne = false , condTwo = false ; if ( ( points [ i ] [ 1 ] - y2 ) * ( x2 - x1 ) - ( y2 - y1 ) * ( points [ i ] [ 0 ] - x2 ) >= 0 ) { condOne = true ; } if ( radius >= Math . sqrt ( Math . pow ( ( y1 - points [ i ] [ 1 ] ) , 2 ) + Math . pow ( x1 - points [ i ] [ 0 ] , 2 ) ) ) { condTwo = true ; } if ( condOne && condTwo ) { ans += 1 ; } } return ans ; } let X = 0 ; let Y = 0 ; let R = 5 ; let P = 5 ; let Q = 0 ; let arr = [ [ 2 , 3 ] , [ 5 , 6 ] , [ - 1 , 4 ] , [ 5 , 5 ] ] ; document . write ( getPointsIns ( X , Y , R , P , Q , arr ) ) ;
Count pairs of points having distance between them equal to integral values in a K | javascript program for the above approach Function to find pairs whose distance between the points of is an integer value . ; Stores count of pairs whose distance between points is an integer ; Traverse the array , points ; Stores distance between points ( i , j ) ; Traverse all the points of current pair ; Update temp ; Update dist ; If dist is a perfect square ; Update ans ; Given value of K ; Given points ; Given value of N ; Function Call
function cntPairs ( points , n , K ) { var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { var dist = 0 ; for ( k = 0 ; k < K ; k ++ ) { var temp = ( points [ i ] [ k ] - points [ j ] [ k ] ) ; dist += temp * temp ; } if ( Math . sqrt ( dist ) * Math . sqrt ( dist ) == dist ) { ans += 1 ; } } } document . write ( ans + " " ) ; } var K = 2 ; var points = [ [ 1 , 2 ] , [ 5 , 5 ] , [ - 2 , 8 ] ] ; var n = points . length ; cntPairs ( points , n , K ) ;
Circumradius of a Cyclic Quadrilateral using the length of Sides | Function to return the circumradius of a cyclic quadrilateral using sides ; Find semiperimeter ; Calculate the radius ; Driver code ; Function call ; Print the radius
function Circumradius ( a , b , c , d ) { var s = ( a + b + c + d ) / 2.0 ; var radius = Math . sqrt ( ( ( a * b ) + ( c * d ) ) * ( ( a * c ) + ( b * d ) ) * ( ( a * d ) + ( b * c ) ) / ( ( s - a ) * ( s - b ) * ( s - c ) * ( s - d ) ) ) ; return radius / 4 ; } var A = 3 ; var B = 4 ; var C = 5 ; var D = 6 ; var ans = Circumradius ( A , B , C , D ) ; document . write ( ans . toFixed ( 2 ) ) ;
Area of Triangle using Side | Function to return the area of triangle using Side - Angle - Side formula ; Driver Code ; Function Call ; Prvar the final answer
function Area_of_Triangle ( a , b , k ) { var area = ( ( 1 / 2.0 ) * a * b * Math . sin ( k ) ) ; return area ; } var a = 9 ; var b = 12 ; var k = 2 ; var ans = Area_of_Triangle ( a , b , k ) ; document . write ( ans . toFixed ( 1 ) ) ;
Find if a point lies inside , outside or on the circumcircle of three points A , B , C | Structure Pointer to store x and y coordinates ; Function to find the line given two points ; Function which converts the input line to its perpendicular bisector . It also inputs the points whose mid - point lies o on the bisector ; Find the mid point ; x coordinates ; y coordinates ; c = - bx + ay ; Assign the coefficient of a and b ; Returns the intersection point of two lines ; Find determinant ; Returns the intersection point of two lines ; Find determinant ; Function to find the point lies inside , outside or on the circle ; Store the coordinates radius of circumcircle ; Line PQ is represented as ax + by = c ; Line QR is represented as ex + fy = g ; Converting lines PQ and QR to perpendicular bisectors . After this , L = ax + by = c M = ex + fy = g ; The point of intersection of L and M gives r as the circumcenter ; Length of radius ; Distance between radius and the given point D ; Condition for point lies inside circumcircle ; Condition for point lies on circumcircle ; Condition for point lies outside circumcircle ; Driver Code ; Given Points ; Function call to find the point lies inside , outside or on the circle
class point { constructor ( x , y ) { this . x = x ; this . y = y ; } } function lineFromPoints ( P , Q , a , b , c ) { a = Q . y - P . y ; b = P . x - Q . x ; c = a * ( P . x ) + b * ( P . y ) ; } function perpenBisectorFromLine ( P , Q , a , b , c ) { let mid_point = new point ( ) ; mid_point . x = ( P . x + Q . x ) / 2 ; mid_point . y = ( P . y + Q . y ) / 2 ; c = - b * ( mid_point . x ) + a * ( mid_point . y ) ; let temp = a ; a = - b ; b = temp ; } function LineInterX ( a1 , b1 , c1 , a2 , b2 , c2 ) { let determ = a1 * b2 - a2 * b1 ; let x = ( b2 * c1 - b1 * c2 ) ; x /= determ ; return x ; } function LineInterY ( a1 , b1 , c1 , a2 , b2 , c2 ) { let determ = a1 * b2 - a2 * b1 ; let y = ( a1 * c2 - a2 * c1 ) ; y /= determ ; return y ; } function findPosition ( P , Q , R , D ) { let r = new point ( ) ; let a = 0 , b = 0 , c = 0 ; lineFromPoints ( P , Q , a , b , c ) ; let e = 0 , f = 0 , g = 0 ; lineFromPoints ( Q , R , e , f , g ) ; perpenBisectorFromLine ( P , Q , a , b , c ) ; perpenBisectorFromLine ( Q , R , e , f , g ) ; r . x = LineInterX ( a , b , c , e , f , g ) ; r . y = LineInterY ( a , b , c , e , f , g ) ; let q = ( r . x - P . x ) * ( r . x - P . x ) + ( r . y - P . y ) * ( r . y - P . y ) ; let dis = ( r . x - D . x ) * ( r . x - D . x ) + ( r . y - D . y ) * ( r . y - D . y ) ; if ( dis < q ) { document . write ( " " + D . x + " " + D . y + " " + " " ) ; } else if ( dis == q ) { document . write ( " " + D . x + " " + D . y + " " + " " ) ; } else { document . write ( " " + D . x + " " + D . y + " " + " " ) ; } } let A , B , C , D ; A = new point ( 2 , 8 ) ; B = new point ( 2 , 1 ) ; C = new point ( 4 , 5 ) ; D = new point ( 3 , 0 ) ; findPosition ( A , B , C , D ) ;
Find the maximum angle at which we can tilt the bottle without spilling any water | javascript program to find the maximum angle at which we can tilt the bottle without spilling any water ; Now we have the volume of rectangular prism a * a * b ; Now we have 2 cases ! ; Taking the tangent inverse of value d As we want to take out the required angle ; Taking the tangent inverse of value d As we want to take out the required angle ; As of now the angle is in radian . So we have to convert it in degree . ; Enter the Base square side length ; Enter the Height of rectangular prism ; Enter the Base square side length
function find_angle ( x , y , z ) { var volume = x * x * y ; var ans = 0 ; if ( z < volume / 2 ) { var d = ( ( x * y * y ) / ( 2.0 * z ) ) ; ans = Math . atan ( d ) ; } else { z = volume - z ; var d = ( 2 * z ) / ( x * x * x ) ; ans = Math . atan ( d ) ; } ans = ( ( ans * 180 ) / 3.14159265 ) ; return ans ; } var x = 12 ; var y = 21 ; var z = 10 ; document . write ( find_angle ( x , y , z ) . toFixed ( 4 ) + " " ) ;
Count of distinct rectangles inscribed in an equilateral triangle | Function to return the count of rectangles when n is odd ; Calculating number of dots in vertical level ; Calculating number of ways to select two points in the horizontal level i ; Multiply both to obtain the number of rectangles formed at that level ; Calculating number of dots in vertical level ; Calculating number of ways to select two points in the horizontal level i ; Multiply both to obtain the number of rectangles formed at that level ; Function to return the count of rectangles when n is even ; Driver code ; If n is odd
function countOdd ( n ) { let coun = 0 , m , j , i ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( i >= 1 ) { m = parseInt ( ( n - i ) / 2 , 10 ) ; j = parseInt ( ( i * ( i + 1 ) ) / 2 , 10 ) ; coun += j * m ; } else { m = parseInt ( ( ( n - 1 ) - i ) / 2 , 10 ) ; j = parseInt ( ( i * ( i + 1 ) ) / 2 , 10 ) ; coun += j * m ; } } return coun ; } function countEven ( n ) { let coun = 0 , m , j , i ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( i >= 1 ) { m = parseInt ( ( ( n - 1 ) - i ) / 2 , 10 ) ; j = parseInt ( ( i * ( i + 1 ) ) / 2 , 10 ) ; coun += j * m ; } else { m = parseInt ( ( n - i ) / 2 , 10 ) ; j = parseInt ( ( i * ( i + 1 ) ) / 2 , 10 ) ; coun += j * m ; } } return coun ; } let n = 5 ; if ( n >= 1 ) document . write ( countOdd ( n ) ) ; else document . write ( countEven ( n ) ) ;
Area of the biggest ellipse inscribed within a rectangle | Function to find the area of the rectangle ; The sides cannot be negative ; Area of the ellipse ; Driver code
function ellipse ( l , b ) { if ( l < 0 b < 0 ) return - 1 ; var x = ( 3.14 * l * b ) / 4 ; return x ; } var a = 5 , b = 3 ; document . write ( ellipse ( a , b ) ) ;
Determine the number of squares of unit area that a given line will pass through . | Function to return the required position ;  ; Driver Code
function noOfSquares ( x1 , y1 , x2 , y2 ) { var dx = Math . abs ( x2 - x1 ) ; var dy = Math . abs ( y2 - y1 ) ; var ans = dx + dy - __gcd ( dx , dy ) ; document . write ( ans ) ; } function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } var x1 = 1 , y1 = 1 , x2 = 4 , y2 = 3 ; noOfSquares ( x1 , y1 , x2 , y2 ) ;
Count paths with distance equal to Manhattan distance | Function to return the value of nCk ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; Function to return the number of paths ; Difference between the ' x ' coordinates of the given points ; Difference between the ' y ' coordinates of the given points ; Driver code
function binomialCoeff ( n , k ) { var res = 1 ; var i ; if ( k > n - k ) k = n - k ; for ( i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function countPaths ( x1 , y1 , x2 , y2 ) { var m = Math . abs ( x1 - x2 ) ; var n = Math . abs ( y1 - y2 ) ; return ( binomialCoeff ( m + n , n ) ) ; } var x1 = 2 , y1 = 3 , x2 = 4 , y2 = 5 ; document . write ( countPaths ( x1 , y1 , x2 , y2 ) ) ;
Find the area of largest circle inscribed in ellipse | Area of the Reuleaux triangle ; Driver Code
function areaCircle ( b ) { let area = 3.1415926 * b * b ; return area ; } let a = 10 , b = 8 ; document . write ( areaCircle ( b ) ) ;
Section formula for 3 D | Function to find the section of the line ; Applying section formula ; Printing result ; Driver code
function section ( x1 , x2 , y1 , y2 , z1 , z2 , m , n ) { let x = ( ( m * x2 ) + ( n * x1 ) ) / ( m + n ) ; let y = ( ( m * y2 ) + ( n * y1 ) ) / ( m + n ) ; let z = ( ( m * z2 ) + ( n * z1 ) ) / ( m + n ) ; document . write ( " " + x + " " ) ; document . write ( y + " " ) ; document . write ( z + " " ) ; } let x1 = 2 , x2 = 4 , y1 = - 1 , y2 = 3 , z1 = 4 , z2 = 2 , m = 2 , n = 3 ; section ( x1 , x2 , y1 , y2 , z1 , z2 , m , n ) ;
Program to find the Circumcircle of any regular polygon | Function to find the radius of the circumcircle ; these cannot be negative ; Radius of the circumcircle ; Return the radius ; Driver code ; Find the radius of the circumcircle
function findRadiusOfcircumcircle ( n , a ) { if ( n < 0 a < 0 ) return - 1 ; var radius = ( a / Math . sqrt ( 2 - ( 2 * Math . cos ( 360 / n ) ) ) ) ; return radius ; } var n = 5 , a = 6 ; document . write ( findRadiusOfcircumcircle ( n , a ) . toFixed ( 5 ) ) ;
Program to find the Radius of the incircle of the triangle | Function to find the radius of the incircle ; the sides cannot be negative ; semi - perimeter of the circle ; area of the triangle ; Radius of the incircle ; Return the radius ; Get the sides of the triangle ; Find the radius of the incircle
function findRadiusOfIncircle ( a , b , c ) { if ( a < 0 b < 0 c < 0 ) return - 1 ; var p = ( a + b + c ) / 2 ; var area = Math . sqrt ( p * ( p - a ) * ( p - b ) * ( p - c ) ) ; var radius = area / p ; return radius ; } var a = 2 , b = 2 , c = 3 ; document . write ( findRadiusOfIncircle ( a , b , c ) . toFixed ( 6 ) ) ;
Find area of triangle if two vectors of two adjacent sides are given | function to calculate area of triangle ; Driver Code
function area ( x1 , y1 , z1 , x2 , y2 , z2 ) { let area = Math . sqrt ( Math . pow ( ( y1 * z2 - y2 * z1 ) , 2 ) + Math . pow ( ( x1 * z2 - x2 * z1 ) , 2 ) + Math . pow ( ( x1 * y2 - x2 * y1 ) , 2 ) ) ; area = area / 2 ; return area ; } let x1 = - 2 ; let y1 = 0 ; let z1 = - 5 ; let x2 = 1 ; let y2 = - 2 ; let z2 = - 1 ; let a = area ( x1 , y1 , z1 , x2 , y2 , z2 ) ; document . write ( " " + a ) ;
Largest trapezoid that can be inscribed in a semicircle | Function to find the area of the biggest trapezoid ; the radius cannot be negative ; area of the trapezoid ; Driver code
function trapezoidarea ( r ) { if ( r < 0 ) return - 1 ; var a = ( 3 * Math . sqrt ( 3 ) * Math . pow ( r , 2 ) ) / 4 ; return a ; } var r = 5 ; document . write ( trapezoidarea ( r ) . toFixed ( 3 ) ) ;
Largest rectangle that can be inscribed in a semicircle | Function to find the area of the biggest rectangle ; the radius cannot be negative ; area of the rectangle ; Driver code
function rectanglearea ( r ) { if ( r < 0 ) return - 1 ; var a = r * r ; return a ; } var r = 5 ; document . write ( parseInt ( rectanglearea ( r ) ) ) ;
Maximum distinct lines passing through a single point | function to find maximum lines which passes through a single point ; Driver Code
function maxLines ( n , x1 , y1 , x2 , y2 ) { var s = [ ] ; var slope = 2147483647 ; for ( let i = 0 ; i < n ; i ++ ) { if ( x1 [ i ] === x2 [ i ] ) slope = 2147483647 ; else slope = ( ( ( y2 [ i ] - y1 [ i ] ) * 1.0 ) / ( x2 [ i ] - x1 [ i ] ) ) * 1.0 ; s . push ( slope ) ; } return s . length ; } var n = 2 ; var x1 = [ 1 , 2 ] ; var y1 = [ 1 , 2 ] ; var x2 = [ 2 , 4 ] ; var y2 = [ 2 , 10 ] ; document . write ( maxLines ( n , x1 , y1 , x2 , y2 ) ) ;
Find area of parallelogram if vectors of two adjacent sides are given | Function to calculate area of parallelogram ; Driver Code
function area ( x1 , y1 , z1 , x2 , y2 , z2 ) { area = Math . sqrt ( Math . pow ( ( y1 * z2 - y2 * z1 ) , 2 ) + Math . pow ( ( x1 * z2 - x2 * z1 ) , 2 ) + Math . pow ( ( x1 * y2 - x2 * y1 ) , 2 ) ) ; return area ; } let x1 = 3 ; let y1 = 1 ; let z1 = - 2 ; let x2 = 1 ; let y2 = - 3 ; let z2 = 4 ; a = area ( x1 , y1 , z1 , x2 , y2 , z2 ) ; document . write ( " " ) ; document . write ( a ) ;
Maximum possible intersection by moving centers of line segments | Function to print the maximum intersection ; Case 1 ; Case 2 ; Case 3 ; driver program
function max_intersection ( center , length , k ) { center . sort ( ) ; if ( center [ 2 ] - center [ 0 ] >= 2 * k + length ) { return 0 ; } else if ( center [ 2 ] - center [ 0 ] >= 2 * k ) { return ( 2 * k - ( center [ 2 ] - center [ 0 ] - length ) ) ; } else return length ; } let center = [ 1 , 2 , 3 ] ; let L = 1 ; let K = 1 ; document . write ( max_intersection ( center , L , K ) ) ;
Haversine formula to find distance between two points on a sphere | Javascript program for the haversine formula ; distance between latitudes and longitudes ; convert to radiansa ; apply formulae ; Driver Code
function haversine ( lat1 , lon1 , lat2 , lon2 ) { let dLat = ( lat2 - lat1 ) * Math . PI / 180.0 ; let dLon = ( lon2 - lon1 ) * Math . PI / 180.0 ; lat1 = ( lat1 ) * Math . PI / 180.0 ; lat2 = ( lat2 ) * Math . PI / 180.0 ; let a = Math . pow ( Math . sin ( dLat / 2 ) , 2 ) + Math . pow ( Math . sin ( dLon / 2 ) , 2 ) * Math . cos ( lat1 ) * Math . cos ( lat2 ) ; let rad = 6371 ; let c = 2 * Math . asin ( Math . sqrt ( a ) ) ; return rad * c ; } let lat1 = 51.5007 ; let lon1 = 0.1246 ; let lat2 = 40.6892 ; let lon2 = 74.0445 ; document . write ( haversine ( lat1 , lon1 , lat2 , lon2 ) + " " ) ;
Pentatope number | Function that returns nth pentatope number ; For 5 th PentaTope Number ; For 11 th PentaTope Number
function pentatopeNum ( n ) { return ( n * ( n + 1 ) * ( n + 2 ) * ( n + 3 ) ) / 24 ; } let n = 5 ; document . write ( pentatopeNum ( n ) + " " ) ; n = 11 ; document . write ( pentatopeNum ( n ) ) ;
Heptagonal number | Function to return Nth Heptagonal number ; Drivers Code
function heptagonalNumber ( n ) { return parseInt ( ( ( 5 * n * n ) - ( 3 * n ) ) / 2 ) ; } let n = 2 ; document . write ( heptagonalNumber ( n ) + " " ) ; n = 15 ; document . write ( heptagonalNumber ( n ) + " " ) ;
Icosidigonal number | Function to calculate Icosidigonal number ; Formula for finding nth Icosidigonal number ; Driver function
function icosidigonal_num ( n ) { return parseInt ( ( 20 * n * n - 18 * n ) / 2 ) ; } let n = 4 ; document . write ( n + " " + icosidigonal_num ( n ) ) ; document . write ( " " ) ; n = 8 ; document . write ( n + " " + icosidigonal_num ( n ) ) ;
Hypercube Graph | function to find power of 2 ; driver program n is the order of the graph
function power ( n ) { if ( n == 1 ) return 2 ; return 2 * power ( n - 1 ) ; } var n = 4 ; document . write ( power ( n ) ) ;
Reflection of a point at 180 degree rotation of another point | Javascript Program to find the 180 degree reflection of one point around another point . ; Driver Code
function findPoint ( x1 , y1 , x2 , y2 ) { document . write ( " " + 2 * ( x2 - x1 ) + " " + 2 * ( y2 - y1 ) + " " ) ; } let x1 = 0 , y1 = 0 , x2 = 1 , y2 = 1 ; findPoint ( x1 , y1 , x2 , y2 ) ;
Program to check if the points are parallel to X axis or Y axis | To check for parallel line ; Checking for parallel to X and Y axis condition ; To display the output ; Driver code
function parallel ( n , a ) { let x = true , y = true ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] [ 0 ] != a [ i + 1 ] [ 0 ] ) x = false ; if ( a [ i ] [ 1 ] != a [ i + 1 ] [ 1 ] ) y = false ; } if ( x ) document . write ( " " + " " ) ; else if ( y ) document . write ( " " + " " ) ; else document . write ( " " + " " + " " ) ; } let a = [ [ 1 , 2 ] , [ 1 , 4 ] , [ 1 , 6 ] , [ 1 , 0 ] ] ; let n = a . length ; parallel ( n , a ) ;
Triangular Matchstick Number | javascript program to find X - th triangular matchstick number ; Driver code
function numberOfSticks ( x ) { return ( 3 * x * ( x + 1 ) ) / 2 ; } document . write ( numberOfSticks ( 7 ) ) ;
Total area of two overlapping rectangles | Javascript program to find total area of two overlapping Rectangles Returns Total Area of two overlap rectangles ; Area of 1 st Rectangle ; Area of 2 nd Rectangle ; Length of intersecting part i . e start from max ( l1 [ x ] , l2 [ x ] ) of x - coordinate and end at min ( r1 [ x ] , r2 [ x ] ) x - coordinate by subtracting start from end we get required lengths ; Driver Code ; Function call
function overlappingArea ( l1 , r1 , l2 , r2 ) { let x = 0 let y = 1 let area1 = Math . abs ( l1 [ x ] - r1 [ x ] ) * Math . abs ( l1 [ y ] - r1 [ y ] ) let area2 = Math . abs ( l2 [ x ] - r2 [ x ] ) * Math . abs ( l2 [ y ] - r2 [ y ] ) let x_dist = ( Math . min ( r1 [ x ] , r2 [ x ] ) - Math . max ( l1 [ x ] , l2 [ x ] ) ) let y_dist = ( Math . min ( r1 [ y ] , r2 [ y ] ) - Math . max ( l1 [ y ] , l2 [ y ] ) ) let areaI = 0 if ( x_dist > 0 && y_dist > 0 ) areaI = x_dist * y_dist return ( area1 + area2 - areaI ) } let l1 = [ 2 , 2 ] let r1 = [ 5 , 7 ] let l2 = [ 3 , 4 ] let r2 = [ 6 , 9 ] document . write ( overlappingArea ( l1 , r1 , l2 , r2 ) )
Area of square Circumscribed by Circle | Function to find area of square ; Radius of a circle ; Call Function to find an area of square
function find_Area ( r ) { return ( 2 * r * r ) ; } let r = 3 ; document . write ( " " + find_Area ( r ) ) ;
Check whether triangle is valid or not if sides are given | function to check if three sider form a triangle or not ; check condition ; Driver function ; function calling and print output
function checkValidity ( a , b , c ) { if ( a + b <= c a + c <= b b + c <= a ) return false ; else return true ; } let a = 7 , b = 10 , c = 5 ; if ( checkValidity ( a , b , c ) ) document . write ( " " ) ; else document . write ( " " ) ;