codeparrot/xlcost-text-to-code huggingface dataset:
Diagonal of a Regular Heptagon | C ++ Program to find the diagonal of a regular heptagon ; Function to return the diagonal of a regular heptagon ; Side cannot be negative ; Length of the diagonal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float heptdiagonal ( float a ) { if ( a < 0 ) return -1 ; float d = 1.802 * a ; return d ; } int main ( ) { float a = 6 ; cout << heptdiagonal ( a ) << endl ; return 0 ; }
Diagonal of a Regular Hexagon | C ++ Program to find the diagonal of a regular hexagon ; Function to find the diagonal of a regular hexagon ; Side cannot be negative ; Length of the diagonal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float hexDiagonal ( float a ) { if ( a < 0 ) return -1 ; float d = 1.73 * a ; return d ; } int main ( ) { float a = 9 ; cout << hexDiagonal ( a ) << endl ; return 0 ; }
Area of Reuleaux Triangle | C ++ Program to find the area of Reuleaux triangle ; Function to find the Area of the Reuleaux triangle ; Side cannot be negative ; Area of the Reuleaux triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float ReuleauxArea ( float a ) { if ( a < 0 ) return -1 ; float A = 0.70477 * pow ( a , 2 ) ; return A ; } int main ( ) { float a = 6 ; cout << ReuleauxArea ( a ) << endl ; return 0 ; }
Largest Square that can be inscribed within a hexagon | C ++ program to find the area of the largest square that can be inscribed within the hexagon ; Function to find the area of the square ; Side cannot be negative ; Area of the square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float squareArea ( float a ) { if ( a < 0 ) return -1 ; float area = pow ( 1.268 , 2 ) * pow ( a , 2 ) ; return area ; } int main ( ) { float a = 6 ; cout << squareArea ( a ) << endl ; return 0 ; }
Volume of cube using its space diagonal | C ++ program to find the volume occupied by Cube with given space diagonal ; Function to calculate Volume ; Formula to find Volume ; Drivers code ; space diagonal of Cube
#include <bits/stdc++.h> NEW_LINE using namespace std ; float CubeVolume ( float d ) { float Volume ; Volume = ( sqrt ( 3 ) * pow ( d , 3 ) ) / 9 ; return Volume ; } int main ( ) { float d = 5 ; cout << " Volume ▁ of ▁ Cube : ▁ " << CubeVolume ( d ) ; return 0 ; }
Length of rope tied around three equal circles touching each other | C ++ program to find the length of rope ; Function to find the length of rope ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define PI  3.14159265 NEW_LINE float length_rope ( float r ) { return ( ( 2 * PI * r ) + 6 * r ) ; } int main ( ) { float r = 7 ; cout << ceil ( length_rope ( r ) ) << endl ; return 0 ; }
Number of triangles that can be formed with given N points | C ++ implementation of the above approach ; This function returns the required number of triangles ; Hash Map to store the frequency of slope corresponding to a point ( X , Y ) ; Iterate over all possible points ; Calculate slope of all elements with current element ; find the slope with reduced fraction ; Total number of ways to form a triangle having one point as current element ; Subtracting the total number of ways to form a triangle having the same slope or are collinear ; Driver Code to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countTriangles ( pair < int , int > P [ ] , int N ) { map < pair < int , int > , int > mp ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { mp . clear ( ) ; for ( int j = i + 1 ; j < N ; j ++ ) { int X = P [ i ] . first - P [ j ] . first ; int Y = P [ i ] . second - P [ j ] . second ; int g = __gcd ( X , Y ) ; X /= g ; Y /= g ; mp [ { X , Y } ] ++ ; } int num = N - ( i + 1 ) ; ans += ( num * ( num - 1 ) ) / 2 ; for ( auto j : mp ) ans -= ( j . second * ( j . second - 1 ) ) / 2 ; } return ans ; } int main ( ) { pair < int , int > P [ ] = { { 0 , 0 } , { 2 , 0 } , { 1 , 1 } , { 2 , 2 } } ; int N = sizeof ( P ) / sizeof ( P [ 0 ] ) ; cout << countTriangles ( P , N ) << endl ; return 0 ; }
Area of Circumcircle of a Right Angled Triangle | C ++ program to find the area of Cicumscribed circle of right angled triangle ; Function to find area of circumscribed circle ; Driver code
#include <bits/stdc++.h> NEW_LINE #define PI  3.14159265 NEW_LINE using namespace std ; float area_circumscribed ( float c ) { return ( c * c * ( PI / 4 ) ) ; } int main ( ) { float c = 8 ; cout << area_circumscribed ( c ) ; return 0 ; }
Largest right circular cylinder that can be inscribed within a cone | C ++ Program to find the biggest right circular cylinder that can be fit within a right circular 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; float cyl ( float r , float h ) { if ( r < 0 && h < 0 ) return -1 ; float R = ( 2 * r ) / 3 ; float H = ( 2 * h ) / 3 ; float V = 3.14 * pow ( R , 2 ) * H ; return V ; } int main ( ) { float r = 4 , h = 8 ; cout << cyl ( r , h ) << endl ; return 0 ; }
Largest cube that can be inscribed within a right circular cylinder | C ++ Program to find the biggest cube 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; float cube ( float h , float r ) { if ( h < 0 && r < 0 ) return -1 ; float a = pow ( h , 3 ) ; return a ; } int main ( ) { float h = 5 , r = 4 ; cout << cube ( h , r ) << endl ; return 0 ; }
Volume of biggest sphere within a right circular cylinder | C ++ Program to find the biggest sphere that can be fit within a right circular cylinder ; Function to find the biggest sphere ; radius and height cannot be negative ; radius of sphere ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float sph ( float r , float h ) { if ( r < 0 && h < 0 ) return -1 ; float R = r ; return R ; } int main ( ) { float r = 4 , h = 8 ; cout << sph ( r , h ) << endl ; return 0 ; }
Volume of largest right circular cylinder within a Sphere | C ++ Program to find the biggest right circular cylinder that can be fit within a sphere ; Function to find the biggest right circular cylinder ; radius cannot be negative ; volume of cylinder ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float cyl ( float R ) { if ( R < 0 ) return -1 ; float V = ( 2 * 3.14 * pow ( R , 3 ) ) / ( 3 * sqrt ( 3 ) ) ; return V ; } int main ( ) { float R = 4 ; cout << cyl ( R ) << endl ; return 0 ; }
Longest rod that can be inserted within a right circular cylinder | C ++ Program to find the longest rod that can be fit within a right circular cylinder ; Function to find the side of the cube ; height and radius cannot be negative ; length of rod ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float rod ( float h , float r ) { if ( h < 0 && r < 0 ) return -1 ; float l = sqrt ( pow ( h , 2 ) + 4 * pow ( r , 2 ) ) ; return l ; } int main ( ) { float h = 4 , r = 1.5 ; cout << rod ( h , r ) << endl ; return 0 ; }
Largest cube that can be inscribed within a right circular cone | C ++ Program to find the biggest cube 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; float cubeSide ( float h , float r ) { if ( h < 0 && r < 0 ) return -1 ; float a = ( h * r * sqrt ( 2 ) ) / ( h + sqrt ( 2 ) * r ) ; return a ; } int main ( ) { float h = 5 , r = 6 ; cout << cubeSide ( h , r ) << endl ; return 0 ; }
Largest right circular cone that can be inscribed within a sphere | C ++ Program to find the biggest 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; float coner ( float R ) { if ( R < 0 ) return -1 ; float r = ( 2 * sqrt ( 2 ) * R ) / 3 ; return r ; } float coneh ( float R ) { if ( R < 0 ) return -1 ; float h = ( 4 * R ) / 3 ; return h ; } int main ( ) { float R = 10 ; cout << " r ▁ = ▁ " << coner ( R ) << " , ▁ " << " h ▁ = ▁ " << coneh ( R ) << endl ; return 0 ; }
Largest cone that can be inscribed within a cube | C ++ Program to find the biggest cone 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; float coneRadius ( float a ) { if ( a < 0 ) return -1 ; float r = a / sqrt ( 2 ) ; return r ; } float coneHeight ( float a ) { if ( a < 0 ) return -1 ; float h = a ; return h ; } int main ( ) { float a = 6 ; cout << " r ▁ = ▁ " << coneRadius ( a ) << " , ▁ " << " h ▁ = ▁ " << coneHeight ( a ) << endl ; return 0 ; }
Largest cube that can be inscribed within the sphere | C ++ Program to find the biggest cube inscribed within a sphere ; Function to find the side of the cube ; radius cannot be negative ; side of the cube ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float largestCube ( float r ) { if ( r < 0 ) return -1 ; float a = ( 2 * r ) / sqrt ( 3 ) ; return a ; } int main ( ) { float r = 5 ; cout << largestCube ( r ) << endl ; return 0 ; }
Largest sphere that can be inscribed inside a cube | C ++ Program to find the biggest sphere inscribed within a cube ; Function to find the radius of the sphere ; side cannot be negative ; radius of the sphere ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float sphere ( float a ) { if ( a < 0 ) return -1 ; float r = a / 2 ; return r ; } int main ( ) { float a = 5 ; cout << sphere ( a ) << endl ; return 0 ; }
Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts | C ++ implementation of above approach ; function that calculates the maximum no . of cuts ; Driver Code ; Calling function .
#include <bits/stdc++.h> NEW_LINE using namespace std ; int numberOfCuts ( int M , int N ) { int result = 0 ; result = ( M - 1 ) * ( N - 1 ) ; return result ; } int main ( ) { int M = 4 , N = 4 ; int Cuts = numberOfCuts ( M , N ) ; cout << " Maximum ▁ cuts ▁ = ▁ " << Cuts ; return 0 ; }
Find maximum volume of a cuboid from the given perimeter and area | C ++ implementation of the above approach ; function to return maximum volume ; calculate length ; calculate volume ; return result ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; float maxVol ( float P , float A ) { float l = ( P - sqrt ( P * P - 24 * A ) ) / 12 ; float V = l * ( A / 2.0 - l * ( P / 4.0 - l ) ) ; return V ; } int main ( ) { float P = 20 , A = 16 ; cout << maxVol ( P , A ) ; return 0 ; }
Program to calculate area and perimeter of a rhombus whose diagonals are given | C ++ Program to calculate area and perimeter of a rhombus using diagonals ; calculate area and perimeter of a rhombus ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int rhombusAreaPeri ( int d1 , int d2 ) { long long int area , perimeter ; area = ( d1 * d2 ) / 2 ; perimeter = 2 * sqrt ( pow ( d1 , 2 ) + pow ( d2 , 2 ) ) ; cout << " The ▁ area ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " << d1 << " ▁ and ▁ " << d2 << " ▁ is ▁ " << area << " . " << endl ; cout << " The ▁ perimeter ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " << d1 << " ▁ and ▁ " << d2 << " ▁ is ▁ " << perimeter << " . " << endl ; } int main ( ) { int d1 = 2 , d2 = 4 ; rhombusAreaPeri ( d1 , d2 ) ; return 0 ; }
Area of decagon inscribed within the circle | C ++ Program to find the area of the decagon inscribed within a circle ; Function to find the area of the decagon ; radius cannot be negative ; area of the decagon ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float area ( float r ) { if ( r < 0 ) return -1 ; float area = ( 5 * pow ( r , 2 ) * ( 3 - sqrt ( 5 ) ) * ( sqrt ( 5 ) + ( 2 * sqrt ( 5 ) ) ) ) / 4 ; return area ; } int main ( ) { float r = 8 ; cout << area ( r ) << endl ; return 0 ; }
Maximum area of rectangle possible with given perimeter | C ++ to find maximum area rectangle ; Function to find max area ; return area ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxArea ( float perimeter ) { int length = ( int ) ceil ( perimeter / 4 ) ; int breadth = ( int ) floor ( perimeter / 4 ) ; return length * breadth ; } int main ( ) { float n = 38 ; cout << " Maximum ▁ Area ▁ = ▁ " << maxArea ( n ) ; return 0 ; }
Find the foot of perpendicular of a point in a 3 D plane | C ++ program to find foot of perpendicular of a point in a 3 D plane . ; Function to find foot of perpendicular ; Driver Code ; function call
#include <bits/stdc++.h> NEW_LINE #include <iomanip> NEW_LINE #include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void foot ( float a , float b , float c , float d , float x1 , float y1 , float z1 ) { float k = ( - a * x1 - b * y1 - c * z1 - d ) / ( float ) ( a * a + b * b + c * c ) ; float x2 = a * k + x1 ; float y2 = b * k + y1 ; float z2 = c * k + z1 ; std :: cout << std :: fixed ; std :: cout << std :: setprecision ( 1 ) ; cout << " ▁ x2 ▁ = ▁ " << x2 ; cout << " ▁ y2 ▁ = ▁ " << y2 ; cout << " ▁ z2 ▁ = ▁ " << z2 ; } int main ( ) { float a = 1 ; float b = -2 ; float c = 0 ; float d = 0 ; float x1 = -1 ; float y1 = 3 ; float z1 = 4 ; foot ( a , b , c , d , x1 , y1 , z1 ) ; return 0 ; }
Equation of parabola from its focus and directrix | C ++ program to find equation of a parbola using focus and directrix . ; Function to find equation of parabola . ; Driver Code
#include <bits/stdc++.h> NEW_LINE #include <iomanip> NEW_LINE #include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void equation_parabola ( float x1 , float y1 , float a , float b , float c ) { float t = a * a + b * b ; float a1 = t - ( a * a ) ; float b1 = t - ( b * b ) ; float c1 = ( -2 * t * x1 ) - ( 2 * c * a ) ; float d1 = ( -2 * t * y1 ) - ( 2 * c * b ) ; float e1 = -2 * a * b ; float f1 = ( - c * c ) + ( t * x1 * x1 ) + ( t * y1 * y1 ) ; std :: cout << std :: fixed ; std :: cout << std :: setprecision ( 1 ) ; cout << " equation ▁ of ▁ parabola ▁ is ▁ " << a1 << " ▁ x ^ 2 ▁ + ▁ " << b1 << " ▁ y ^ 2 ▁ + ▁ " << c1 << " ▁ x ▁ + ▁ " << d1 << " ▁ y ▁ + ▁ " << e1 << " ▁ xy ▁ + ▁ " << f1 << " ▁ = ▁ 0 . " ; } int main ( ) { float x1 = 0 ; float y1 = 0 ; float a = 3 ; float b = -4 ; float c = 2 ; equation_parabola ( x1 , y1 , a , b , c ) ; return 0 ; }
Minimum squares to evenly cut a rectangle | CPP 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countRectangles ( int l , int w ) { int squareSide = __gcd ( l , w ) ; return ( l * w ) / ( squareSide * squareSide ) ; } int main ( ) { int l = 4 , w = 6 ; cout << countRectangles ( l , w ) << endl ; return 0 ; }
Equation of circle from center and radius | CPP program to find the equation of circle . ; Function to find the equation of circle ; Printing result ; Driver code
#include <iostream> NEW_LINE using namespace std ; void circle_equation ( double x1 , double y1 , double r ) { double a = -2 * x1 ; double b = -2 * y1 ; double c = ( r * r ) - ( x1 * x1 ) - ( y1 * y1 ) ; cout << " x ^ 2 ▁ + ▁ ( " << a << " ▁ x ) ▁ + ▁ " ; cout << " y ^ 2 ▁ + ▁ ( " << b << " ▁ y ) ▁ = ▁ " ; cout << c << " . " << endl ; } int main ( ) { double x1 = 2 , y1 = -3 , r = 8 ; circle_equation ( x1 , y1 , r ) ; return 0 ; }
Program to find the Area and Perimeter of a Semicircle | C ++ 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 ; driver code ; Get the radius ; Find the area ; Find the perimeter
#include <iostream> NEW_LINE using namespace std ; float area ( float r ) { return ( 0.5 ) * ( 3.14 ) * ( r * r ) ; } float perimeter ( float r ) { return ( 3.14 ) * ( r ) ; } int main ( ) { int r = 10 ; cout << " The ▁ Area ▁ of ▁ Semicircle : ▁ " << area ( r ) << endl ; cout << " The ▁ Perimeter ▁ of ▁ Semicircle : ▁ " << perimeter ( r ) << endl ; return 0 ; }
Check if the given vectors are at equilibrium or not | CPP program to check the equilibrium of three vectors ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkEquilibrium ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 , int x3 , int y3 , int z3 ) { int resx = x1 + x2 + x3 ; int resy = y1 + y2 + y3 ; int resz = z1 + z2 + z3 ; if ( resx == 0 and resy == 0 and resz == 0 ) return true ; else return false ; } int main ( ) { int 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 ) ) cout << " The ▁ vectors ▁ are ▁ at ▁ equilibrium . " ; else cout << " The ▁ vectors ▁ are ▁ not ▁ at ▁ equilibrium . " ; return 0 ; }
Find Tangent at a given point on the curve | C ++ program for find Tangent on a curve at given point ; 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 ; Driver code ; declare variable ; call function findTangent
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findTangent ( int A , int x , int y ) { int dif = A - x * 2 ; if ( y == ( 2 * x - x * x ) ) { if ( dif < 0 ) cout << " y ▁ = ▁ " << dif << " x " << ( x * dif ) + ( y ) ; else if ( dif > 0 ) cout << " y ▁ = ▁ " << dif << " x + " << - x * dif + y ; else cout << " Not ▁ possible " ; } } int main ( ) { int A = 2 , x = 2 , y = 0 ; findTangent ( A , x , y ) ; return 0 ; }
Find Four points such that they form a square whose sides are parallel to x and y axes | C ++ implemenataion of the above approach ; find the largest square ; map to store which points exist ; mark the available points ; a nested loop to choose the opposite corners of square ; remove the chosen point ; remove the chosen point ; check if the other two points exist ; if the square is largest then store it ; add the removed point ; add the removed point ; display the largest square ; Driver code ; given points ; find the largest square
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findLargestSquare ( long long int points [ ] [ 2 ] , int n ) { map < pair < long long int , long long int > , int > m ; for ( int i = 0 ; i < n ; i ++ ) { m [ make_pair ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] ++ ; } long long int side = -1 , x = -1 , y = -1 ; for ( int i = 0 ; i < n ; i ++ ) { m [ make_pair ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] -- ; for ( int j = 0 ; j < n ; j ++ ) { m [ make_pair ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] -- ; if ( i != j && ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) == ( points [ i ] [ 1 ] - points [ j ] [ 1 ] ) ) { if ( m [ make_pair ( points [ i ] [ 0 ] , points [ j ] [ 1 ] ) ] > 0 && m [ make_pair ( points [ j ] [ 0 ] , points [ i ] [ 1 ] ) ] > 0 ) { if ( side < abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) || ( side == abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) && ( ( points [ i ] [ 0 ] * points [ i ] [ 0 ] + points [ i ] [ 1 ] * points [ i ] [ 1 ] ) < ( x * x + y * y ) ) ) ) { x = points [ i ] [ 0 ] ; y = points [ i ] [ 1 ] ; side = abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) ; } } } m [ make_pair ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] ++ ; } m [ make_pair ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] ++ ; } if ( side != -1 ) cout << " Side ▁ of ▁ the ▁ square ▁ is ▁ : ▁ " << side << " points of the square are " ▁ < < ▁ x ▁ < < ▁ " , " ▁ < < ▁ y << " ▁ " << ( x + side ) << " , ▁ " << y << " ▁ " << ( x ) << " , ▁ " << ( y + side ) << " ▁ " << ( x + side ) << " , ▁ " << ( y + side ) << endl ; else cout < < " No ▁ such ▁ square " << endl ; } int main ( ) { int n = 6 ; long long int points [ n ] [ 2 ] = { { 1 , 1 } , { 4 , 4 } , { 3 , 4 } , { 4 , 3 } , { 1 , 4 } , { 4 , 1 } } ; findLargestSquare ( points , n ) ; return 0 ; }
Find length of Diagonal of Hexagon | C ++ Program to find the diagonal of the hexagon ; Function to find the diagonal of the hexagon ; side cannot be negative ; diagonal of the hexagon ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float hexadiagonal ( float a ) { if ( a < 0 ) return -1 ; return 2 * a ; } int main ( ) { float a = 4 ; cout << hexadiagonal ( a ) << endl ; return 0 ; }
Program to find the side of the Octagon inscribed within the square | C ++ Program to find the side of the octagon which can be inscribed within the square ; Function to find the side of the octagon ; side cannot be negative ; side of the octagon ; Driver code ; Get he square side ; Find the side length of the square
#include <bits/stdc++.h> NEW_LINE using namespace std ; float octaside ( float a ) { if ( a < 0 ) return -1 ; float s = a / ( sqrt ( 2 ) + 1 ) ; return s ; } int main ( ) { float a = 4 ; cout << octaside ( a ) << endl ; return 0 ; }
Check whether it is possible to join two points given on circle such that distance between them is k | C ++ program to implement above approach ; Return distance between the centers ; Distance between centers ; Case 5 ; SubCase 1 ; Subcase 2 ; Case 1 ; Case 3 ; Case 4 ; Case 2 ; Since value of k will always be an integer ; Driver Code
#include <bits/stdc++.h> NEW_LINE #define ll  long long int NEW_LINE using namespace std ; struct t { ll x , y , r ; } ; typedef struct t node ; long double dis ( ll x1 , ll y1 , ll x2 , ll y2 ) { return sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ; } bool check ( node c1 , node c2 , int k ) { long double min = 0 ; long double max = 0 ; long double de = dis ( c1 . x , c1 . y , c2 . x , c2 . y ) ; if ( de == 0 ) { if ( c1 . r == c2 . r ) { min = 0 ; max = 0 ; } else { if ( c1 . r - c2 . r > 0 ) { min = c1 . r - c2 . r ; max = min + 2 * c2 . r ; } else { min = c2 . r - c1 . r ; max = min + 2 * c1 . r ; } } } else if ( de >= c1 . r + c2 . r ) { min = de - c1 . r - c2 . r ; max = de + c1 . r + c2 . r ; } else if ( de + c2 . r < c1 . r ) { max = c2 . r + c1 . r + de ; min = c1 . r - de - c2 . r ; } else if ( de + c1 . r < c2 . r ) { max = c2 . r + c1 . r + de ; min = c2 . r - de - c1 . r ; } else if ( ( de + c2 . r >= c1 . r ) || ( de + c1 . r >= c2 . r ) ) { max = c2 . r + c1 . r + de ; min = 0 ; } ll temin = ( ll ) ( ceil ( min ) ) ; ll re = ( ll ) max ; if ( k >= temin && k <= re ) return true ; return false ; } int main ( ) { node circle1 , circle2 ; int k = 3 ; circle1 . x = 0 ; circle1 . y = 0 ; circle1 . r = 5 ; circle2 . x = 8 ; circle2 . y = 3 ; circle2 . r = 2 ; if ( check ( circle1 , circle2 , k ) ) cout << " YES " << endl ; else cout << " NO " << endl ; }
Check if it is possible to move from ( 0 , 0 ) to ( x , y ) in N steps | CPP program to check whether it is possible or not to move from ( 0 , 0 ) to ( x , y ) in exactly 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool Arrive ( int a , int b , int n ) { if ( n >= abs ( a ) + abs ( b ) and ( n - ( abs ( a ) + abs ( b ) ) ) % 2 == 0 ) return true ; return false ; } int main ( ) { int a = 5 , b = 5 , n = 11 ; if ( Arrive ( a , b , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }