codeparrot/xlcost-text-to-code huggingface dataset:
Angle between a Pair of Lines | C ++ program for the above approach ; Function to find the angle between two lines ; Store the tan value of the angle ; Calculate tan inverse of the angle ; Convert the angle from radian to degree ; Print the result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define PI  3.14159265 NEW_LINE void findAngle ( double M1 , double M2 ) { double angle = abs ( ( M2 - M1 ) / ( 1 + M1 * M2 ) ) ; double ret = atan ( angle ) ; double val = ( ret * 180 ) / PI ; cout << val ; } int main ( ) { double M1 = 1.75 , M2 = 0.27 ; findAngle ( M1 , M2 ) ; return 0 ; }
Angle of intersection of two circles having their centers D distance apart | C ++ program for the above approach ; Function to find the cosine of the angle of the intersection of two circles with radius R1 and R2 ; Return the cosine of the angle ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float angle ( float R1 , float R2 , float D ) { float ans = ( R1 * R1 + R2 * R2 - D * D ) / ( 2 * R1 * R2 ) ; return ans ; } int main ( ) { float R1 = 3 , R2 = 4 ; float D = 5 ; cout << angle ( R1 , R2 , D ) ; return 0 ; }
Check if any point exists in a plane whose Manhattan distance is at most K from N given points | C ++ program for the above approach ; Function to check if there exists any point with at most K distance from N given points ; Traverse the given N points ; Stores the count of pairs of coordinates having Manhattan distance <= K ; For the same coordinate ; Calculate Manhattan distance ; If Manhattan distance <= K ; If all coordinates can meet ; If all coordinates can 't meet ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string find ( int a [ ] , int b [ ] , int N , int K ) { for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( i == j ) { continue ; } long long int dis = abs ( a [ i ] - a [ j ] ) + abs ( b [ i ] - b [ j ] ) ; if ( dis <= K ) { count ++ ; } if ( count == N - 1 ) { return " Yes " ; } } } return " No " ; } int main ( ) { int N = 5 ; int A [ ] = { 1 , 0 , 2 , 1 , 1 } ; int B [ ] = { 1 , 1 , 1 , 0 , 2 } ; int K = 1 ; cout << find ( A , B , N , K ) << endl ; }
Minimum area of the triangle formed by any tangent to an ellipse with the coordinate axes | C ++ program for the above approach ; Function to find the minimum area of triangle formed by any tangent to ellipse with the coordinate axes ; Stores the minimum area ; Print the calculated area ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void minimumTriangleArea ( int a , int b ) { int area = a * b ; cout << area ; } int main ( ) { int a = 1 , b = 2 ; minimumTriangleArea ( a , b ) ; return 0 ; }
Find interior angles for each side of a given Cyclic Quadrilateral | C ++ program for the above approach ; Function to find the interior angles of the cyclic quadrilateral ; Stores the numerator and the denominator to find angle A ; Stores the numerator and the denominator to find angle B ; Stores the numerator and the denominator to find angle C : ; Stores the numerator and the denominator to find angle D : ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findAngles ( double a , double b , double c , double d ) { double numerator = a * a + d * d - b * b - c * c ; double denominator = 2 * ( a * b + c * d ) ; double x = numerator / denominator ; cout << fixed << setprecision ( 2 ) << " A : ▁ " << ( acos ( x ) * 180 ) / 3.141592 << " ▁ degrees " ; numerator = a * a + b * b - c * c - d * d ; x = numerator / denominator ; cout << fixed << setprecision ( 2 ) << " STRNEWLINE B : ▁ " << ( acos ( x ) * 180 ) / 3.141592 << " ▁ degrees " ; numerator = c * c + b * b - a * a - d * d ; x = numerator / denominator ; cout << fixed << setprecision ( 2 ) << " STRNEWLINE C : ▁ " << ( acos ( x ) * 180 ) / 3.141592 << " ▁ degrees " ; numerator = d * d + c * c - a * a - b * b ; x = numerator / denominator ; cout << fixed << setprecision ( 2 ) << " STRNEWLINE D : ▁ " << ( acos ( x ) * 180 ) / 3.141592 << " ▁ degrees " ; } int main ( ) { double A = 10 , B = 15 , C = 20 , D = 25 ; findAngles ( A , B , C , D ) ; return 0 ; }
Number of smaller circles that can be inscribed in a larger circle | C ++ program for the above approach ; Function to count number of smaller circles that can be inscribed in the larger circle touching its boundary ; If R2 is greater than R1 ; Stores the angle made by the smaller circle ; Stores the ratio of R2 / ( R1 - R2 ) ; Stores the count of smaller circles that can be inscribed ; Stores the ratio ; If the diameter of smaller circle is greater than the radius of the larger circle ; Otherwise ; Find the angle using formula ; Divide 360 with angle and take the floor value ; Return the final result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countInscribed ( int R1 , int R2 ) { if ( R2 > R1 ) return 0 ; double angle ; double ratio ; int number_of_circles = 0 ; ratio = R2 / ( double ) ( R1 - R2 ) ; if ( R1 < 2 * R2 ) { number_of_circles = 1 ; } else { angle = abs ( asin ( ratio ) * 180 ) / 3.14159265 ; number_of_circles = 360 / ( 2 * floor ( angle ) ) ; } return number_of_circles ; } int main ( ) { int R1 = 3 ; int R2 = 1 ; cout << countInscribed ( R1 , R2 ) ; return 0 ; }
Count pairs of coordinates connected by a line with slope in the range [ | C ++ program for the above approach ; Function to find the number of pairs of points such that the line passing through them has a slope in the range [ - k , k ] ; Store the result ; Traverse through all the combination of points ; If pair satisfies the given condition ; Increment ans by 1 ; Print the result ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findPairs ( vector < int > x , vector < int > y , int K ) { int n = x . size ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = i + 1 ; j < n ; ++ j ) { if ( K * abs ( x [ i ] - x [ j ] ) >= abs ( y [ i ] - y [ j ] ) ) { ++ ans ; } } } cout << ans ; } int main ( ) { vector < int > X = { 2 , 1 , 0 } , Y = { 1 , 2 , 0 } ; int K = 1 ; findPairs ( X , Y , K ) ; return 0 ; }
Number of largest circles that can be inscribed in a rectangle | C ++ program for the above approach ; Function to count the number of largest circles in a rectangle ; If length exceeds breadth ; Swap to reduce length to smaller than breadth ; Return total count of circles inscribed ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int totalCircles ( int L , int B ) { if ( L > B ) { int temp = L ; L = B ; B = temp ; } return B / L ; } int main ( ) { int L = 3 ; int B = 8 ; cout << totalCircles ( L , B ) ; return 0 ; }
Program to calculate length of diagonal of a square | C ++ program for the above approach ; Function to find the length of the diagonal of a square of a given side ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double findDiagonal ( double s ) { return sqrt ( 2 ) * s ; } int main ( ) { double S = 10 ; cout << findDiagonal ( S ) ; return 0 ; }
Area of largest isosceles triangle that can be inscribed in an Ellipse whose vertex coincides with one extremity of the major axis | C ++ program for the above approach ; Function to calculate area of the isosceles triangle ; If a and b are negative ; Stores the area of the triangle ; Print the area ; Driver code ; Given value of a & b ; Function call to find the area of the isosceles triangle
#include <bits/stdc++.h> NEW_LINE using namespace std ; void triangleArea ( float a , float b ) { if ( a < 0 b < 0 ) { cout << -1 ; return ; } float area = ( 3 * sqrt ( 3 ) * a * b ) / ( 4 ) ; cout << area ; } int main ( ) { float a = 1 , b = 2 ; triangleArea ( a , b ) ; return 0 ; }
Queries to count points lying on or inside an isosceles Triangle with given length of equal sides | C ++ implementation of above approach ; Function to find answer of each query ; Stores the count of points with sum less than or equal to their indices ; Traverse the array ; If both x and y - coordinate < 0 ; Stores the sum of co - ordinates ; Increment count of sum by 1 ; Prefix array ; Perform queries ; Drivers Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int const MAX = 1e6 + 5 ; int query ( vector < vector < float > > arr , vector < int > Q ) { int pre [ MAX ] = { 0 } ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( arr [ i ] [ 0 ] < 0 arr [ i ] [ 1 ] < 0 ) continue ; int sum = ceil ( ( arr [ i ] [ 0 ] + arr [ i ] [ 1 ] ) ) ; pre [ sum ] ++ ; } for ( int i = 1 ; i < MAX ; i ++ ) pre [ i ] += pre [ i - 1 ] ; for ( int i = 0 ; i < Q . size ( ) ; i ++ ) { cout << pre [ Q [ i ] ] << " ▁ " ; } cout << endl ; } int main ( ) { vector < vector < float > > arr = { { 2.1 , 3.0 } , { 3.7 , 1.2 } , { 1.5 , 6.5 } , { 1.2 , 0.0 } } ; vector < int > Q = { 2 , 8 , 5 } ; int N = arr . size ( ) ; int M = Q . size ( ) ; query ( arr , Q ) ; }
Perimeter of the Union of Two Rectangles | C ++ program for the above approach ; Function to check if two rectangles are intersecting or not ; If one rectangle is to the right of other 's right edge ; If one rectangle is on the top of other 's top edge ; Function to return the perimeter of the Union of Two Rectangles ; Stores the resultant perimeter ; If rectangles do not interesect ; Perimeter of Rectangle 1 ; Perimeter of Rectangle 2 ; If the rectangles intersect ; Get width of combined figure ; Get length of combined figure ; Return the perimeter ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool doIntersect ( vector < int > X , vector < int > Y ) { if ( X [ 0 ] > X [ 3 ] X [ 2 ] > X [ 1 ] ) return false ; if ( Y [ 0 ] > Y [ 3 ] Y [ 2 ] > Y [ 1 ] ) return false ; return true ; } int getUnionPerimeter ( vector < int > X , vector < int > Y ) { int perimeter = 0 ; if ( ! doIntersect ( X , Y ) ) { perimeter += 2 * ( abs ( X [ 1 ] - X [ 0 ] ) + abs ( Y [ 1 ] - Y [ 0 ] ) ) ; perimeter += 2 * ( abs ( X [ 3 ] - X [ 2 ] ) + abs ( Y [ 3 ] - Y [ 2 ] ) ) ; } else { int w = * max_element ( X . begin ( ) , X . end ( ) ) - * min_element ( X . begin ( ) , X . end ( ) ) ; int l = * max_element ( Y . begin ( ) , Y . end ( ) ) - * min_element ( Y . begin ( ) , Y . end ( ) ) ; perimeter = 2 * ( l + w ) ; } return perimeter ; } int main ( ) { vector < int > X { -1 , 2 , 4 , 6 } ; vector < int > Y { 2 , 5 , 3 , 7 } ; cout << getUnionPerimeter ( X , Y ) ; }
Check whether two straight lines are parallel or not | C ++ program for the above approach ; Function to check if two lines are parallel or not ; If slopes are equal ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void parallel ( float a1 , float b1 , float c1 , float a2 , float b2 , float c2 ) { if ( ( - ( a1 / b1 ) ) == ( - ( a2 / b2 ) ) ) { cout << " Yes " ; } else { cout << " No " ; } } int main ( ) { float a1 = -2 , b1 = 4 , c1 = 5 ; float a2 = -6 , b2 = 12 , c2 = 6 ; parallel ( a1 , b1 , c1 , a2 , b2 , c2 ) ; return 0 ; }
Calculate area and height of an isosceles triangle whose sides are radii of a circle | C ++ program for the above approach ; Function to convert given angle from degree to radian ; Function to calculate height and area of the triangle OAB ; Stores the angle OAB and OBA ; Stores the angle in radians ; Stores the height ; Print height of the triangle ; Stores the base of triangle OAB ; Stores the area of the triangle ; Print the area of triangle OAB ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double Convert ( double degree ) { double pi = 3.14159265359 ; return ( degree * ( pi / 180 ) ) ; } void areaAndHeightOfTraingle ( double radius , double a ) { if ( a >= 180 a == 0 ) { cout << " Not ▁ possible " ; return ; } double base_angle = ( 180 - a ) / 2 ; double radians = Convert ( base_angle ) ; double height = sin ( radians ) * radius ; cout << " Height ▁ of ▁ triangle ▁ " << height << endl ; double base = cos ( radians ) * radius ; double area = base * height ; cout << " Area ▁ of ▁ triangle ▁ " << area << endl ; } int main ( ) { double R = 5 , angle = 120 ; areaAndHeightOfTraingle ( R , angle ) ; return 0 ; }
Radius of a circle having area equal to the sum of area of the circles having given radii | C ++ implementation of the above approach ; Function to calculate radius of the circle having area equal to sum of the area of two circles with given radii ; Area of first circle ; Area of second circle ; Area of third circle ; Radius of third circle ; Driver Code ; Given radius ; Prints the radius of the required circle
#include <bits/stdc++.h> NEW_LINE using namespace std ; double findRadius ( double r1 , double r2 ) { double a1 , a2 , a3 , r3 ; a1 = 3.14 * r1 * r1 ; a2 = 3.14 * r2 * r2 ; a3 = a1 + a2 ; r3 = sqrt ( a3 / 3.14 ) ; return r3 ; } int main ( ) { double r1 = 8 , r2 = 6 ; cout << findRadius ( r1 , r2 ) ; return 0 ; }
Minimum number of Cuboids required to form a Cube | C ++ program for the above approach ; Function to calculate and return LCM of a , b , and c ; Find GCD of a and b ; Find LCM of a and b ; LCM ( a , b , c ) = LCM ( LCM ( a , b ) , c ) ; Finding LCM of a , b , c ; return LCM ( a , b , c ) ; Function to find the minimum number of cuboids required to make the volume of a valid cube ; Find the LCM of L , B , H ; Volume of the cube ; Volume of the cuboid ; Minimum number cuboids required to form a cube ; Driver Code ; Given dimensions of cuboid ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int find_lcm ( int a , int b , int c ) { int g = __gcd ( a , b ) ; int LCM1 = ( a * b ) / g ; g = __gcd ( LCM1 , c ) ; int LCM = ( LCM1 * c ) / g ; return LCM ; } void minimumCuboids ( int L , int B , int H ) { int lcm = find_lcm ( L , B , H ) ; int volume_cube = lcm * lcm * lcm ; int volume_cuboid = L * B * H ; cout << ( volume_cube / volume_cuboid ) ; } int main ( ) { int L = 1 , B = 1 , H = 2 ; minimumCuboids ( L , B , H ) ; return 0 ; }
Check if given polygon is a convex polygon or not | C ++ program to implement the above approach ; Utility function to find cross product of two vectors ; Stores coefficient of X direction of vector A [ 1 ] A [ 0 ] ; Stores coefficient of Y direction of vector A [ 1 ] A [ 0 ] ; Stores coefficient of X direction of vector A [ 2 ] A [ 0 ] ; Stores coefficient of Y direction of vector A [ 2 ] A [ 0 ] ; Return cross product ; Function to check if the polygon is convex polygon or not ; Stores count of edges in polygon ; Stores direction of cross product of previous traversed edges ; Stores direction of cross product of current traversed edges ; Traverse the array ; Stores three adjacent edges of the polygon ; Update curr ; If curr is not equal to 0 ; If direction of cross product of all adjacent edges are not same ; Update curr ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int CrossProduct ( vector < vector < int > > & A ) { int X1 = ( A [ 1 ] [ 0 ] - A [ 0 ] [ 0 ] ) ; int Y1 = ( A [ 1 ] [ 1 ] - A [ 0 ] [ 1 ] ) ; int X2 = ( A [ 2 ] [ 0 ] - A [ 0 ] [ 0 ] ) ; int Y2 = ( A [ 2 ] [ 1 ] - A [ 0 ] [ 1 ] ) ; return ( X1 * Y2 - Y1 * X2 ) ; } bool isConvex ( vector < vector < int > > & points ) { int N = points . size ( ) ; int prev = 0 ; int curr = 0 ; for ( int i = 0 ; i < N ; i ++ ) { vector < vector < int > > temp = { points [ i ] , points [ ( i + 1 ) % N ] , points [ ( i + 2 ) % N ] } ; curr = CrossProduct ( temp ) ; if ( curr != 0 ) { if ( curr * prev < 0 ) { return false ; } else { prev = curr ; } } } return true ; } int main ( ) { vector < vector < int > > points = { { 0 , 0 } , { 0 , 1 } , { 1 , 1 } , { 1 , 0 } } ; if ( isConvex ( points ) ) { cout << " Yes " << " STRNEWLINE " ; } else { cout << " No " << " STRNEWLINE " ; } }
Program to find all possible triangles having same Area and Perimeter | C ++ program for the above approach ; Function to print sides of all the triangles having same perimeter & area ; Stores unique sides of triangles ; i + j + k values cannot exceed 256 ; Find the value of 2 * s ; Find the value of 2 * ( s - a ) ; Find the value of 2 * ( s - b ) ; Find the value of 2 * ( s - c ) ; If triplets have same area and perimeter ; Store sides of triangle ; Sort the triplets ; Inserting in set to avoid duplicate sides ; Print sides of all desired triangles ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void samePerimeterAndArea ( ) { set < vector < int > > se ; for ( int i = 1 ; i <= 256 ; ++ i ) { for ( int j = 1 ; j <= 256 ; ++ j ) { for ( int k = 1 ; k <= 256 ; ++ k ) { int peri = i + j + k ; int mul1 = - i + j + k ; int mul2 = i - j + k ; int mul3 = i + j - k ; if ( 16 * peri == mul1 * mul2 * mul3 ) { vector < int > v = { i , j , k } ; sort ( v . begin ( ) , v . end ( ) ) ; se . insert ( v ) ; } } } } for ( auto it : se ) { cout << it [ 0 ] << " ▁ " << it [ 1 ] << " ▁ " << it [ 2 ] << endl ; } } int main ( ) { samePerimeterAndArea ( ) ; return 0 ; }
Count number of triangles cut by the given horizontal and vertical line segments | C ++ program for the above approach ; Store the minimum and maximum X and Y coordinates ; Function to convert string to int ; Function to print the number of triangles cut by each line segment ; Initialize Structure ; Find maximum and minimum X and Y coordinates for each triangle ; Minimum X ; Maximum X ; Minimum Y ; Maximum Y ; Traverse each cut from 0 to M - 1 ; Store number of triangles cut ; Extract value from the line segment string ; If cut is made on X - axis ; Check for each triangle if x lies b / w max and min X coordinates ; If cut is made on Y - axis ; Check for each triangle if y lies b / w max and min Y coordinates ; Print answer for ith cut ; Driver Code ; Given coordinates of triangles ; Given cuts of lines ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Tri { int MinX , MaxX , MinY , MaxY ; } ; int StringtoInt ( string s ) { stringstream geek ( s ) ; int x ; geek >> x ; return x ; } int TriangleCuts ( vector < vector < int > > Triangle , string Cuts [ ] , int N , int M , int COL ) { Tri Minimized [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int x1 = Triangle [ i ] [ 0 ] ; int y1 = Triangle [ i ] [ 1 ] ; int x2 = Triangle [ i ] [ 2 ] ; int y2 = Triangle [ i ] [ 3 ] ; int x3 = Triangle [ i ] [ 4 ] ; int y3 = Triangle [ i ] [ 5 ] ; Minimized [ i ] . MinX = min ( { x1 , x2 , x3 } ) ; Minimized [ i ] . MaxX = max ( { x1 , x2 , x3 } ) ; Minimized [ i ] . MinY = min ( { y1 , y2 , y3 } ) ; Minimized [ i ] . MaxY = max ( { y1 , y2 , y3 } ) ; } for ( int i = 0 ; i < M ; i ++ ) { string Cut = Cuts [ i ] ; int CutCount = 0 ; int CutVal = StringtoInt ( Cut . substr ( 2 , Cut . size ( ) ) ) ; if ( Cut [ 0 ] == ' X ' ) { for ( int j = 0 ; j < N ; j ++ ) { if ( ( Minimized [ j ] . MinX ) < ( CutVal ) & & ( Minimized [ j ] . MaxX ) > ( CutVal ) ) { CutCount ++ ; } } } else if ( Cut [ 0 ] == ' Y ' ) { for ( int j = 0 ; j < N ; j ++ ) { if ( ( Minimized [ j ] . MinY ) < ( CutVal ) & & ( Minimized [ j ] . MaxY ) > ( CutVal ) ) { CutCount ++ ; } } } cout << CutCount << " ▁ " ; } } int main ( ) { vector < vector < int > > Triangle = { { 0 , 2 , 2 , 9 , 8 , 5 } , { 5 , 0 , 6 , 3 , 7 , 0 } } ; int N = Triangle . size ( ) ; int COL = 6 ; string Cuts [ ] = { " X = 2" , " Y = 2" , " Y = 9" } ; int M = sizeof ( Cuts ) / sizeof ( Cuts [ 0 ] ) ; TriangleCuts ( Triangle , Cuts , N , M , COL ) ; return 0 ; }
Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points | C ++ program to implement the above approach ; Function to get the count of ractangles ; Store distinct horizontal lines ; Store distinct Vertical lines ; Insert horizontal line passing through 0 ; Insert vertical line passing through 0. ; Insert horizontal line passing through rectangle [ 3 ] [ 0 ] ; Insert vertical line passing through rectangle [ 3 ] [ 1 ] ; Insert all horizontal and vertical lines passing through the given array ; Insert all horizontal lines ; Insert all vertical lines ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int cntRect ( int points [ ] [ 2 ] , int N , int rectangle [ ] [ 2 ] ) { unordered_set < int > cntHor ; unordered_set < int > cntVer ; cntHor . insert ( 0 ) ; cntVer . insert ( 0 ) ; cntHor . insert ( rectangle [ 3 ] [ 0 ] ) ; cntVer . insert ( rectangle [ 3 ] [ 1 ] ) ; for ( int i = 0 ; i < N ; i ++ ) { cntHor . insert ( points [ i ] [ 0 ] ) ; cntVer . insert ( points [ i ] [ 1 ] ) ; } return ( cntHor . size ( ) - 1 ) * ( cntVer . size ( ) - 1 ) ; } int main ( ) { int rectangle [ ] [ 2 ] = { { 0 , 0 } , { 0 , 5 } , { 5 , 0 } , { 5 , 5 } } ; int points [ ] [ 2 ] = { { 1 , 2 } , { 3 , 4 } } ; int N = sizeof ( points ) / sizeof ( points [ 0 ] ) ; cout << cntRect ( points , N , rectangle ) ; }
Count squares possible from M and N straight lines parallel to X and Y axis respectively | C ++ program for the above approach ; Function to count all the possible squares with given lines parallel to both the X and Y axis ; Stores the count of all possible distances in X [ ] & Y [ ] respectively ; Find distance between all pairs in the array X [ ] ; Add the count to m1 ; Find distance between all pairs in the array Y [ ] ; Add the count to m2 ; Find sum of m1 [ i ] * m2 [ i ] for same distance ; Find current count in m2 ; Add to the total count ; Return the final count ; Driver Code ; Given lines ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int numberOfSquares ( int X [ ] , int Y [ ] , int N , int M ) { unordered_map < int , int > m1 , m2 ; int i , j , ans = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { int dist = abs ( X [ i ] - X [ j ] ) ; m1 [ dist ] ++ ; } } for ( i = 0 ; i < M ; i ++ ) { for ( j = i + 1 ; j < M ; j ++ ) { int dist = abs ( Y [ i ] - Y [ j ] ) ; m2 [ dist ] ++ ; } } for ( auto i = m1 . begin ( ) ; i != m1 . end ( ) ; i ++ ) { if ( m2 . find ( i -> first ) != m2 . end ( ) ) { ans += ( i -> second * m2 [ i -> first ] ) ; } } return ans ; } int main ( ) { int X [ ] = { 1 , 3 , 7 } ; int Y [ ] = { 2 , 4 , 6 , 1 } ; int N = sizeof ( X ) / sizeof ( X [ 0 ] ) ; int M = sizeof ( Y ) / sizeof ( Y [ 0 ] ) ; cout << numberOfSquares ( X , Y , N , M ) ; return 0 ; }
Program to calculate area of a parallelogram | C ++ program for the above approach ; Function to return the area of parallelogram using sides and angle at the intersection of diagonal ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using sides and angle at the intersection of sides ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using diagonals and angle at the intersection of diagonals ; Calculate area of parallelogram ; Return the answer ; Driver Code ; Given diagonal and angle ; Function call ; Print the area
#include <bits/stdc++.h> NEW_LINE using namespace std ; double toRadians ( int degree ) { double pi = 3.14159265359 ; return ( ( double ) degree * ( pi / 180 ) ) ; } double Area_Parallelogram1 ( int a , int b , int theta ) { double area = ( abs ( tan ( toRadians ( theta ) ) ) / 2 ) * abs ( a * a - b * b ) ; return area ; } double Area_Parallelogram2 ( int a , int b , int gamma ) { double area = ( abs ( sin ( toRadians ( gamma ) ) ) ) * abs ( a * b ) ; return area ; } static double Area_Parallelogram3 ( int d1 , int d2 , int theta ) { double area = ( abs ( sin ( toRadians ( theta ) ) ) / 2 ) * abs ( d1 * d2 ) ; return area ; } int main ( ) { int d1 = 3 ; int d2 = 5 ; int theta = 90 ; double area = Area_Parallelogram3 ( d1 , d2 , theta ) ; printf ( " % .2f " , area ) ; }
Count squares of size K inscribed in a square of size N | C ++ implementation of the above approach ; Function to calculate the number of squares of size K in a square of size N ; Stores the number of squares ; Driver Code ; Size of the bigger square ; Size of smaller square
#include <iostream> NEW_LINE using namespace std ; int No_of_squares ( int N , int K ) { int no_of_squares = 0 ; no_of_squares = ( N - K + 1 ) * ( N - K + 1 ) ; return no_of_squares ; } int main ( ) { int N = 5 ; int K = 3 ; cout << No_of_squares ( N , K ) ; return 0 ; }