codeparrot/xlcost-text-to-code huggingface dataset:
Largest Square that can be inscribed within a hexagon | Function to find the area of the square ; Side cannot be negative ; Area of the square ; Driver code
< ? php function squareArea ( $ a ) { if ( $ a < 0 ) return -1 ; $ area = pow ( 1.268 , 2 ) * pow ( $ a , 2 ) ; return $ area ; } $ a = 6 ; echo squareArea ( $ a ) , " STRNEWLINE " ; ? >
Volume of cube using its space diagonal | Function to calculate Volume ; Formula to find Volume ; space diagonal of Cube
< ? php function CubeVolume ( $ d ) { $ Volume ; $ Volume = ( sqrt ( 3 ) * pow ( $ d , 3 ) ) / 9 ; return $ Volume ; } $ d = 5 ; echo " Volume ▁ of ▁ Cube : ▁ " , CubeVolume ( $ d ) ; ? >
Perimeter and Area of Varignon 's Parallelogram | Function to find the perimeter ; Function to find the area ; Driver code
< ? php function per ( $ a , $ b ) { return ( $ a + $ b ) ; } function area ( $ s ) { return ( $ s / 2 ) ; } $ a = 7 ; $ b = 8 ; $ s = 10 ; echo ( per ( $ a , $ b ) " " ) ; echo " STRNEWLINE " ; echo ( area ( $ s ) ) ; ? >
Area of a leaf inside a square | PHP program to find the area of leaf inside a square ; Function to find area of leaf ; Driver code
< ? php $ PI = 3.14159265 ; function area_leaf ( $ a ) { global $ PI ; return ( $ a * $ a * ( $ PI / 2 - 1 ) ) ; } $ a = 7 ; echo ( area_leaf ( $ a ) ) ; ? >
Length of rope tied around three equal circles touching each other | PHP program to find the length of rope ; Function to find the length of rope ; Driver code
< ? php $ PI = 3.14159265 ; function length_rope ( $ r ) { global $ PI ; return ( ( 2 * $ PI * $ r ) + 6 * $ r ) ; } $ r = 7 ; echo ( length_rope ( $ r ) ) ; ? >
Area of Incircle of a Right Angled Triangle | PHP program to find the area of inscribed circle of right angled triangle ; Function to find area of inscribed circle ; Driver code
< ? php $ PI = 3.14159265 ; function area_inscribed ( $ P , $ B , $ H ) { global $ PI ; return ( ( $ P + $ B - $ H ) * ( $ P + $ B - $ H ) * ( $ PI / 4 ) ) ; } $ P = 3 ; $ B = 4 ; $ H = 5 ; echo ( area_inscribed ( $ P , $ B , $ H ) ) ; ? >
Area of Circumcircle of a Right Angled Triangle | PHP program to find the area of Cicumscribed circle of right angled triangle ; Function to find area of circumscribed circle ; Driver code
< ? php $ PI = 3.14159265 ; function area_circumscribed ( $ c ) { global $ PI ; return ( $ c * $ c * ( $ PI / 4 ) ) ; } $ c = 8 ; echo ( area_circumscribed ( $ c ) ) ; ? >
Largest right circular cylinder that can be inscribed within a cone | Function to find the biggest right circular cylinder ; radius and height cannot be negative ; radius of right circular cylinder ; height of right circular cylinder ; volume of right circular cylinder ; Driver code
< ? php function cyl ( $ r , $ h ) { if ( $ r < 0 && $ h < 0 ) return -1 ; $ R = ( int ) ( 2 * $ r ) / 3 ; $ H = ( int ) ( 2 * $ h ) / 3 ; $ V = 3.14 * pow ( $ R , 2 ) * $ H ; return $ V ; } $ r = 4 ; $ h = 8 ; echo cyl ( $ r , $ h ) ; ? >
Largest cube that can be inscribed within a right circular cylinder | Function to find the volume of the cube ; height and radius cannot be negative ; volume of the cube ; Driver code
< ? php function cube ( $ h , $ r ) { if ( $ h < 0 && $ r < 0 ) return -1 ; $ a = pow ( $ h , 3 ) ; return $ a ; } $ h = 5 ; $ r = 4 ; echo cube ( $ h , $ r ) ; ? >
Volume of biggest sphere within a right circular cylinder | Function to find the biggest sphere ; radius and height cannot be negative ; radius of sphere ; Driver code
< ? php function sph ( $ r , $ h ) { if ( $ r < 0 && $ h < 0 ) return -1 ; $ R = $ r ; return $ R ; } $ r = 4 ; $ h = 8 ; echo sph ( $ r , $ h ) ; ? >
Volume of largest right circular cylinder within a Sphere | Function to find the biggest right circular cylinder ; radius cannot be negative ; volume of cylinder ; Driver code
< ? php function cyl ( $ R ) { if ( $ R < 0 ) return -1 ; $ V = ( 2 * 3.14 * pow ( $ R , 3 ) ) / ( 3 * sqrt ( 3 ) ) ; return $ V ; } $ R = 4 ; echo cyl ( $ R ) ; ? >
Longest rod that can be inserted within a right circular cylinder | Function to find the side of the cube ; height and radius cannot be negative ; length of rod ; Driver code
< ? php function rod ( $ h , $ r ) { if ( $ h < 0 && $ r < 0 ) return -1 ; $ l = sqrt ( pow ( $ h , 2 ) + 4 * pow ( $ r , 2 ) ) ; return $ l ; } $ h = 4 ; $ r = 1.5 ; echo rod ( $ h , $ r ) . " STRNEWLINE " ; ? >
Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle | PHP program to find the area of inscribed circle of equilateral triangle ; function to find area of inscribed circle ; function to find perimeter of inscribed circle ; Driver code
< ? php $ PI = 3.14159265 ; function area_inscribed ( $ a ) { global $ PI ; return ( $ a * $ a * ( $ PI / 12 ) ) ; } function perm_inscribed ( $ a ) { global $ PI ; return ( $ PI * ( $ a / sqrt ( 3 ) ) ) ; } $ a = 6 ; echo ( " Area ▁ of ▁ inscribed ▁ circle ▁ is ▁ : " ) ; echo ( area_inscribed ( $ a ) ) ; echo ( " Perimeter ▁ of ▁ inscribed ▁ circle ▁ is ▁ : " ) ; echo ( perm_inscribed ( $ a ) ) ; ? >
Largest cube that can be inscribed within a right circular cone | Function to find the side of the cube ; height and radius cannot be negative ; side of the cube ; Driver code
< ? php function cubeSide ( $ h , $ r ) { if ( $ h < 0 && $ r < 0 ) return -1 ; $ a = ( $ h * $ r * sqrt ( 2 ) ) / ( $ h + sqrt ( 2 ) * $ r ) ; return $ a ; } $ h = 5 ; $ r = 6 ; echo cubeSide ( $ h , $ r ) ; ? >
Largest right circular cone that can be inscribed within a sphere | Function to find the radius of the cone ; radius cannot be negative ; radius of the cone ; Function to find the height of the cone ; side cannot be negative ; height of the cone ; Driver code
< ? php function coner ( $ R ) { if ( $ R < 0 ) return -1 ; $ r = ( 2 * sqrt ( 2 ) * $ R ) / 3 ; return $ r ; } function coneh ( $ R ) { if ( $ R < 0 ) return -1 ; $ h = ( 4 * $ R ) / 3 ; return $ h ; } $ R = 10 ; echo ( " r ▁ = ▁ " ) ; echo coner ( $ R ) ; echo ( " , ▁ " ) ; echo ( " h ▁ = ▁ " ) ; echo ( coneh ( $ R ) ) ; ? >
Largest cone that can be inscribed within a cube | Function to find the radius of the cone ; side cannot be negative ; radius of the cone ; Function to find the height of the cone ; side cannot be negative ; height of the cone ; Driver code
< ? php function coneRadius ( $ a ) { if ( $ a < 0 ) return -1 ; $ r = $ a / sqrt ( 2 ) ; return $ r ; } function coneHeight ( $ a ) { if ( $ a < 0 ) return -1 ; $ h = $ a ; return $ h ; } $ a = 6 ; echo ( " r ▁ = ▁ " ) ; echo coneRadius ( $ a ) ; echo ( " , ▁ " ) ; echo ( " h ▁ = ▁ " ) ; echo ( coneHeight ( $ a ) ) ; ? >
Largest cube that can be inscribed within the sphere | Function to find the side of the cube ; radius cannot be negative ; side of the cube ; Driver code
< ? php function largestCube ( $ r ) { if ( $ r < 0 ) return -1 ; $ a = ( float ) ( ( 2 * $ r ) / sqrt ( 3 ) ) ; return $ a ; } $ r = 5 ; echo largestCube ( $ r ) ; ? >
Largest sphere that can be inscribed inside a cube | Function to find the radius of the sphere ; side cannot be negative ; radius of the sphere ; Driver code
< ? php function sphere ( $ a ) { if ( $ a < 0 ) return -1 ; $ r = ( $ a / 2 ) ; return $ r ; } $ a = 5 ; echo sphere ( $ a ) ; ? >
Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts | function that calculates the maximum no . of cuts ; Driver Code ; Calling function .
< ? php function numberOfCuts ( $ M , $ N ) { $ result = 0 ; $ result = ( $ M - 1 ) * ( $ N - 1 ) ; return $ result ; } $ M = 4 ; $ N = 4 ; $ Cuts = numberOfCuts ( $ M , $ N ) ; echo " Maximum ▁ cuts ▁ = ▁ " , $ Cuts ; ? >
Find maximum volume of a cuboid from the given perimeter and area | function to return maximum volume ; calculate length ; calculate volume ; return result ; Driver code ; Function call
< ? php function maxVol ( $ P , $ A ) { $ l = ( $ P - sqrt ( $ P * $ P - 24 * $ A ) ) / 12 ; $ V = $ l * ( $ A / 2.0 - $ l * ( $ P / 4.0 - $ l ) ) ; return $ V ; } $ P = 20 ; $ A = 16 ; echo maxVol ( $ P , $ A ) ; ? >
Program to calculate area and perimeter of a rhombus whose diagonals are given | calculate area and perimeter of a rhombus ; Driver code
< ? php function rhombusAreaPeri ( $ d1 , $ d2 ) { $ area = ( $ d1 * $ d2 ) / 2 ; $ perimeter = 2 * sqrt ( pow ( $ d1 , 2 ) + pow ( $ d2 , 2 ) ) ; echo " The ▁ area ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " . $ d1 . " ▁ and ▁ " . $ d2 . " ▁ is ▁ " . $ area . " . " . " STRNEWLINE " ; echo " The ▁ perimeter ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " . $ d1 . " ▁ and ▁ " . $ d2 . " ▁ is ▁ " . $ perimeter . " . " . " STRNEWLINE " ; } $ d1 = 2 ; $ d2 = 4 ; rhombusAreaPeri ( $ d1 , $ d2 ) ; ? >
Area of decagon inscribed within the circle | Function to find the area of the decagon ; radius cannot be negative ; area of the decagon ; Driver code
< ? php function area ( $ r ) { if ( $ r < 0 ) return -1 ; $ area = ( 5 * pow ( $ r , 2 ) * ( 3 - sqrt ( 5 ) ) * ( sqrt ( 5 ) + ( 2 * sqrt ( 5 ) ) ) ) / 4 ; return $ area ; } $ r = 8 ; echo area ( $ r ) . " STRNEWLINE " ; ? >
Maximum area of rectangle possible with given perimeter | Function to find max area ; return area ; Driver code
< ? php function maxArea ( $ perimeter ) { $ length = ( int ) ceil ( $ perimeter / 4 ) ; $ breadth = ( int ) floor ( $ perimeter / 4 ) ; return ( $ length * $ breadth ) ; } $ n = 38 ; echo " Maximum ▁ Area ▁ = ▁ " , maxArea ( $ n ) ; ? >
Find the foot of perpendicular of a point in a 3 D plane | Function to find foot of perpendicular ; Driver Code ; function call
< ? php function foot ( $ a , $ b , $ c , $ d , $ x1 , $ y1 , $ z1 ) { $ k = ( - $ a * $ x1 - $ b * $ y1 - $ c * $ z1 - $ d ) / ( $ a * $ a + $ b * $ b + $ c * $ c ) ; $ x2 = $ a * $ k + $ x1 ; $ y2 = $ b * $ k + $ y1 ; $ z2 = $ c * $ k + $ z1 ; echo " x2 = " ▁ . ▁ round ( $ x2 , ▁ 1 ) ; STRNEWLINE TABSYMBOL echo ▁ " y2 = " ▁ . ▁ round ( $ y2 , ▁ 1 ) ; STRNEWLINE TABSYMBOL echo ▁ " z2 = " } $ a = 1 ; $ b = -2 ; $ c = 0 ; $ d = 0 ; $ x1 = -1 ; $ y1 = 3 ; $ z1 = 4 ; foot ( $ a , $ b , $ c , $ d , $ x1 , $ y1 , $ z1 ) ; ? >
Minimum squares to evenly cut a rectangle | PHP program to find minimum number of squares to make a given rectangle . ; if we take gcd ( l , w ) , this will be largest possible side for square , hence minimum number of square . ; Number of squares . ; Driver code
< ? php function gcd ( $ a , $ b ) { return $ b ? gcd ( $ b , $ a % $ b ) : $ a ; } function countRectangles ( $ l , $ w ) { $ squareSide = gcd ( $ l , $ w ) ; return ( $ l * $ w ) / ( $ squareSide * $ squareSide ) ; } $ l = 4 ; $ w = 6 ; echo countRectangles ( $ l , $ w ) . " STRNEWLINE " ; ? >
Equation of circle from center and radius | Function to find the equation of circle ; Printing result ; Driver code
< ? php function circle_equation ( $ x1 , $ y1 , $ r ) { $ a = -2 * $ x1 ; $ b = -2 * $ y1 ; $ c = ( $ r * $ r ) - ( $ x1 * $ x1 ) - ( $ y1 * $ y1 ) ; echo " x ^ 2 + ( " ▁ . ▁ $ a ▁ . ▁ " x ) + " echo " y ^ 2 ▁ + ▁ ( " . $ b . " ▁ y ) ▁ = ▁ " ; echo $ c . " . " . " STRNEWLINE " ; } $ x1 = 2 ; $ y1 = -3 ; $ r = 8 ; circle_equation ( $ x1 , $ y1 , $ r ) ; ? >
Program to find the Area and Perimeter of a Semicircle | Function for calculating the area ; Formula for finding the area ; Function for calculating the perimeter ; Formula for finding the perimeter ; Get the radius ; Find the area ; Find the perimeter
< ? php function area ( $ r ) { return ( 0.5 ) * ( 3.14 ) * ( $ r * $ r ) ; } function perimeter ( $ r ) { return ( 3.14 ) * ( $ r ) ; } $ r = 10 ; echo " The ▁ Area ▁ of ▁ Semicircle : ▁ " , area ( $ r ) , " STRNEWLINE " ; echo " The ▁ Perimeter ▁ of ▁ Semicircle : ▁ " , perimeter ( $ r ) , " STRNEWLINE " ; ? >
Check if the given vectors are at equilibrium or not | Function to check the equilibrium of three vectors ; summing the x coordinates ; summing the y coordinates ; summing the z coordinates ; Checking the condition for equilibrium ; Driver code ; Checking for equilibrium
< ? php function checkEquilibrium ( $ x1 , $ y1 , $ z1 , $ x2 , $ y2 , $ z2 , $ x3 , $ y3 , $ z3 ) { $ resx = $ x1 + $ x2 + $ x3 ; $ resy = $ y1 + $ y2 + $ y3 ; $ resz = $ z1 + $ z2 + $ z3 ; if ( $ resx == 0 and $ resy == 0 and $ resz == 0 ) return true ; else return false ; } $ x1 = -2 ; $ y1 = -7 ; $ z1 = -9 ; $ x2 = 5 ; $ y2 = -14 ; $ z2 = 14 ; $ x3 = -3 ; $ y3 = 21 ; $ z3 = -5 ; if ( checkEquilibrium ( $ x1 , $ y1 , $ z1 , $ x2 , $ y2 , $ z2 , $ x3 , $ y3 , $ z3 ) ) echo " The ▁ vectors ▁ are ▁ at ▁ equilibrium . " ; else echo " The ▁ vectors ▁ are ▁ not ▁ at ▁ equilibrium . " ; ? >
Find Tangent at a given point on the curve | function for find Tangent ; differentiate given equation ; check that point on the curve or not ; if differentiate is negative ; differentiate is positive ; differentiate is zero ; declare variable ; call function findTangent
< ? php function findTangent ( $ A , $ x , $ y ) { $ dif = $ A - $ x * 2 ; if ( $ y == ( 2 * $ x - $ x * $ x ) ) { if ( $ dif < 0 ) echo " y = " , ▁ $ dif ▁ , ▁ " x " ( $ x * $ dif ) + ( $ y ) ; else if ( $ dif > 0 ) echo " y ▁ = ▁ " , $ dif , " x + " , - $ x * $ dif + $ y ; else echo " Not ▁ possible " ; } } $ A = 2 ; $ x = 2 ; $ y = 0 ; findTangent ( $ A , $ x , $ y ) ; ? >
Find length of Diagonal of Hexagon | Function to find the diagonal of the hexagon ; side cannot be negative ; diagonal of the hexagon ; Driver code
< ? php function hexadiagonal ( $ a ) { if ( $ a < 0 ) return -1 ; return 2 * $ a ; } $ a = 4 ; echo hexadiagonal ( $ a ) ; ? >
Program to find the side of the Octagon inscribed within the square | Function to find the side of the octagon ; side cannot be negative ; side of the octagon ; Get he square side ; Find the side length of the square
< ? php function octaside ( $ a ) { if ( $ a < 0 ) return -1 ; $ s = $ a / ( sqrt ( 2 ) + 1 ) ; return $ s ; } $ a = 4 ; echo octaside ( $ a ) ; ? >
Check if it is possible to move from ( 0 , 0 ) to ( x , y ) in N steps | Function to check whether it is possible or not to move from ( 0 , 0 ) to ( x , y ) in exactly n steps ; Driver code
< ? php function Arrive ( $ a , $ b , $ n ) { if ( $ n >= abs ( $ a ) + abs ( $ b ) and ( $ n - ( abs ( $ a ) + abs ( $ b ) ) ) % 2 == 0 ) return true ; return false ; } $ a = 5 ; $ b = 5 ; $ n = 11 ; if ( Arrive ( $ a , $ b , $ n ) ) echo " Yes " ; else echo " No " ;
Check if it is possible to move from ( a , 0 ) to ( b , 0 ) with given jumps | Function to check if it is possible ; Driver code ; function call
< ? php function Move ( $ a , $ x , $ b ) { if ( ( ( ( $ b - $ a ) % $ x == 0 ) || ( ( $ b - $ a - 1 ) % $ x == 0 ) && $ a + 1 != $ b ) && $ b >= $ a ) return true ; return false ; } $ a = 3 ; $ x = 2 ; $ b = 7 ; if ( Move ( $ a , $ x , $ b ) ) echo " Yes " ; else echo " No " ; ? >
Area of a triangle inscribed in a rectangle which is inscribed in an ellipse | Function to find the area of the triangle ; length of a and b cannot be negative ; area of the triangle ; Driver code
< ? php function area ( $ a , $ b ) { if ( $ a < 0 $ b < 0 ) return -1 ; $ A = $ a * $ b ; return $ A ; } $ a = 5 ; $ b = 2 ; echo area ( $ a , $ b ) ; ? >
Circumradius of the rectangle | Function to find the radius of the circumcircle ; the sides cannot be negative ; Radius of the circumcircle ; Return the radius ; Get the sides of the triangle ; Find the radius of the circumcircle
< ? php function findRadiusOfcircumcircle ( $ l , $ b ) { if ( $ l < 0 $ b < 0 ) return -1 ; $ radius = sqrt ( pow ( $ l , 2 ) + pow ( $ b , 2 ) ) / 2 ; return $ radius ; } $ l = 4 ; $ b = 3 ; echo findRadiusOfcircumcircle ( $ l , $ b ) ; ? >
Area of the circumcircle of any triangles with sides given | Function to find the area of the circumcircle ; the sides cannot be negative ; semi - perimeter of the circle ; area of triangle ; area of the circle ; Get the sides of the triangle ; Find and print the area of the circumcircle
< ? php function circlearea ( $ a , $ b , $ c ) { if ( $ a < 0 $ b < 0 $ c < 0 ) return -1 ; $ p = ( $ a + $ b + $ c ) / 2 ; $ At = sqrt ( $ p * ( $ p - $ a ) * ( $ p - $ b ) * ( $ p - $ c ) ) ; $ A = 3.14 * pow ( ( ( $ a * $ b * $ c ) / ( 4 * $ At ) ) , 2 ) ; return $ A ; } $ a = 4 ; $ b = 5 ; $ c = 3 ; echo circlearea ( $ a , $ b , $ c ) ; ? >
Find the altitude and area of an isosceles triangle | function to find the altitude ; return altitude ; function to find the area ; return area ; Driver Code
< ? php function altitude ( $ a , $ b ) { return sqrt ( pow ( $ a , 2 ) - ( pow ( $ b , 2 ) / 4 ) ) ; } function area ( $ b , $ h ) { return ( 1 * $ b * $ h ) / 2 ; } $ a = 2 ; $ b = 3 ; $ h = altitude ( $ a , $ b ) ; echo " Altitude = " ▁ , ▁ $ h ▁ , ▁ " , " echo " Area ▁ = ▁ " , area ( $ b , $ h ) ; ? >
Program to find the surface area of the square pyramid | function to find the surface area ; Driver Code ; surface area of the square pyramid
< ? php function surfaceArea ( $ b , $ s ) { return 2 * $ b * $ s + pow ( $ b , 2 ) ; } $ b = 3 ; $ s = 4 ; echo surfaceArea ( $ b , $ s ) ; ? >
Area of largest triangle that can be inscribed within a rectangle | Function to find the area of the triangle ; a and b cannot be negative ; area of the triangle ; Driver code
< ? php function trianglearea ( $ l , $ b ) { if ( $ l < 0 or $ b < 0 ) return -1 ; $ area = ( $ l * $ b ) / 2 ; return $ area ; } $ l = 5 ; $ b = 4 ; echo trianglearea ( $ l , $ b ) ; ? >
Check if any square ( with one colored cell ) can be divided into two equal parts | function to check if it 's possible to divide the square in two equal parts ; if the painted square is linked anyway to the center of the square then it 's  not possible ; else yes it 's possible ; initialize the size of the square ; initialize the dimension of the painted square
< ? php function halfsquare ( $ n , $ x , $ y ) { $ half = $ n / 2 ; if ( ( $ half == $ x $ half == $ x - 1 ) && ( $ half == $ y $ half == $ y - 1 ) ) echo " NO " ; else echo " YES " ; } $ n = 100 ; $ x = 51 ; $ y = 100 ; halfsquare ( $ n , $ x , $ y ) ; ? >
Check if it is possible to reach vector B by rotating vector A and adding vector C to it | function to check if vector B is possible from vector A ; if d = 0 , then you need to add nothing to vector A ; for all four quadrants ; initialize all three vector coordinates
< ? php function check ( $ a , $ b , $ p , $ q ) { $ d = $ p * $ p + $ q * $ q ; if ( $ d == 0 ) return ( $ a == 0 && $ b == 0 ) ; else return ( ( $ a * $ p + $ b * $ q ) % $ d == 0 && ( $ b * $ p - $ a * $ q ) % $ d == 0 ) ; } function check1 ( $ a , $ b , $ x , $ y , $ p , $ q ) { if ( check ( $ a - $ x , $ b - $ y , $ p , $ q ) || check ( $ a + $ x , $ b + $ y , $ p , $ q ) || check ( $ a - $ y , $ b + $ x , $ p , $ q ) || check ( $ a + $ y , $ b - $ x , $ p , $ q ) ) return true ; else return false ; } $ a = -4 ; $ b = -2 ; $ x = 0 ; $ y = 0 ; $ p = -2 ; $ q = -1 ; if ( check1 ( $ a , $ b , $ x , $ y , $ p , $ q ) ) echo " Yes " ; else echo " No " ; ? >
Largest triangle that can be inscribed in an ellipse | Function to find the area of the triangle ; a and b cannot be negative ; area of the triangle ; Driver code
< ? php function trianglearea ( $ a , $ b ) { if ( $ a < 0 $ b < 0 ) return -1 ; $ area = ( 3 * sqrt ( 3 ) * pow ( $ a , 2 ) ) / ( 4 * $ b ) ; return $ area ; } $ a = 4 ; $ b = 2 ; echo trianglearea ( $ a , $ b ) ; ? >
Area of the Largest square that can be inscribed in an ellipse | Function to find the area of the square ; a and b cannot be negative ; area of the square ; Driver code
< ? php function squarearea ( $ a , $ b ) { if ( $ a < 0 or $ b < 0 ) return -1 ; $ area = 4 * ( ( ( pow ( $ a , 2 ) + pow ( $ b , 2 ) ) / ( pow ( $ a , 2 ) * pow ( $ b , 2 ) ) ) ) ; return $ area ; } $ a = 4 ; $ b = 2 ; print ( squarearea ( $ a , $ b ) ) ; ? >
Largest triangle that can be inscribed in a semicircle | Function to find the area of the triangle ; the radius cannot be negative ; area of the triangle ; Driver code
< ? php function trianglearea ( $ r ) { if ( $ r < 0 ) return -1 ; return $ r * $ r ; } $ r = 5 ; echo trianglearea ( $ r ) ; ? >
Largest square that can be inscribed in a semicircle | Function to find the area of the square ; the radius cannot be negative ; area of the square ; Driver code
< ? php function squarearea ( $ r ) { if ( $ r < 0 ) return -1 ; $ a = 4 * ( pow ( $ r , 2 ) / 5 ) ; return $ a ; } $ r = 5 ; echo squarearea ( $ r ) ; ? >
Area of Largest rectangle that can be inscribed in an Ellipse | Function to find the area of the rectangle ; a and b cannot be negative ; area of the rectangle ; Driver code
< ? php function rectanglearea ( $ a , $ b ) { if ( $ a < 0 or $ b < 0 ) return -1 ; return 2 * $ a * $ b ; } $ a = 10 ; $ b = 8 ; echo rectanglearea ( $ a , $ b ) ; ? >
Area of a largest square fit in a right angle triangle | Function to find the area of the biggest square ; the height or base or hypotenuse cannot be negative ; side of the square ; squaring to get the area ; Driver code
< ? php function squareArea ( $ l , $ b , $ h ) { if ( $ l < 0 $ b < 0 $ h < 0 ) return -1 ; $ a = ( $ l * $ b ) / ( $ l + $ b ) ; return $ a * $ a ; } $ l = 5 ; $ b = 12 ; $ h = 13 ; echo round ( squareArea ( $ l , $ b , $ h ) , 4 ) ; ? >
Queries to check if it is possible to join boxes in a circle | PHP implementation of above approach ; Print the answer to each query ; setting the flag for exception ; replacing the greater element in i and j ; checking if that box is not used in previous query . ; checking if connecting to the same box ; case 1 : x < i and y lies between i and j ; case 2 : x lies between i and j and y > j ; if flag is not reset inbetween . ; Driver code
< ? php $ MAX = 50 ; function solveQuery ( $ n , $ q , & $ qi , & $ qj ) { global $ MAX ; $ arr = array_fill ( 0 , $ MAX , NULL ) ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) $ arr [ $ i ] = 0 ; for ( $ k = 0 ; $ k < $ q ; $ k ++ ) { $ flag = 0 ; if ( $ qj [ $ k ] < $ qi [ $ k ] ) { $ temp = $ qi [ $ k ] ; $ qi [ $ k ] = $ qj [ $ k ] ; $ qj [ $ k ] = $ temp ; } if ( $ arr [ $ qi [ $ k ] ] != 0 $ arr [ $ qj [ $ k ] ] != 0 ) $ flag = 1 ; else if ( $ qi [ $ k ] == $ qj [ $ k ] ) $ flag = 1 ; else { for ( $ i = 1 ; $ i < $ qi [ $ k ] ; $ i ++ ) { if ( $ arr [ $ i ] != 0 && $ arr [ $ i ] < $ qj [ $ k ] && $ qi [ $ k ] < $ arr [ $ i ] ) { $ flag = 1 ; break ; } } if ( $ flag == 0 ) { for ( $ i = $ qi [ $ k ] + 1 ; $ i < $ qj [ $ k ] ; $ i ++ ) { if ( $ arr [ $ i ] != 0 && $ arr [ $ i ] > $ qj [ $ k ] ) { $ flag = 1 ; break ; } } } } if ( $ flag == 0 ) { echo " YES STRNEWLINE " ; $ arr [ $ qi [ $ k ] ] = $ qj [ $ k ] ; $ arr [ $ qj [ $ k ] ] = $ qi [ $ k ] ; } else echo " NO STRNEWLINE " ; } } $ n = 10 ; $ q = 7 ; $ qi = array ( 1 , 2 , 2 , 2 , 9 , 10 , 8 ) ; $ qj = array ( 5 , 7 , 3 , 4 , 9 , 9 , 6 ) ; solveQuery ( $ n , $ q , $ qi , $ qj ) ; ? >
Minimum squares to cover a rectangle | PHP program to find the minimum number of squares to cover the surface of the rectangle with given dimensions ; function to count the number of squares that can cover the surface of the rectangle ; Driver code
< ? php function squares ( $ l , $ b , $ a ) { return ceil ( $ l / ( double ) $ a ) * ceil ( $ b / ( double ) $ a ) ; } $ l = 11 ; $ b = 23 ; $ a = 14 ; echo squares ( $ l , $ b , $ a ) ; ? >
Smallest square formed with given rectangles | Recursive function to return gcd of a and b ; Everything divides 0 ; Base case ; a is greater ; Function to find the area of the smallest square ; the length or breadth or side cannot be negative ; LCM of length and breadth ; squaring to get the area ; Driver code
< ? php function gcd ( $ a , $ b ) { if ( $ a == 0 $ b == 0 ) return 0 ; if ( $ a == $ b ) return $ a ; if ( $ a > $ b ) return gcd ( $ a - $ b , $ b ) ; return gcd ( $ a , $ b - $ a ) ; } function squarearea ( $ l , $ b ) { if ( $ l < 0 $ b < 0 ) return -1 ; $ n = ( $ l * $ b ) / gcd ( $ l , $ b ) ; return $ n * $ n ; } $ l = 6 ; $ b = 4 ; echo squarearea ( $ l , $ b ) . " STRNEWLINE " ; ? >