codeparrot/xlcost-text-to-code huggingface dataset:
Calculate sum of all integers from 1 to N , excluding perfect power of 2 | C ++ implementation of the approach ; Function to find the required summation ; Find the sum of first N integers using the formula ; Find the sum of numbers which are exact power of 2 by using the formula ; Print the final Sum ; Driver 's Code ; Function to find the sum
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findSum ( int N ) { int sum = ( N ) * ( N + 1 ) / 2 ; int r = log2 ( N ) + 1 ; int expSum = pow ( 2 , r ) - 1 ; cout << sum - expSum << endl ; } int main ( ) { int N = 2 ; findSum ( N ) ; return 0 ; }
Largest Even and Odd N | C ++ implementation of the above approach ; Function to print the largest N - digit even and odd numbers of base B ; Initialise the Number ; If Base B is even , then B ^ n will give largest Even number of N + 1 digit ; To get even number of N digit subtract 2 from B ^ n ; To get odd number of N digit subtract 1 from B ^ n ; If Base B is odd , then B ^ n will give largest Odd number of N + 1 digit ; To get even number of N digit subtract 1 from B ^ n ; To get odd number of N digit subtract 2 from B ^ n ; Driver 's Code ; Function to find the numbers
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findNumbers ( int n , int b ) { int even = 0 , odd = 0 ; if ( b % 2 == 0 ) { even = pow ( b , n ) - 2 ; odd = pow ( b , n ) - 1 ; } else { even = pow ( b , n ) - 1 ; odd = pow ( b , n ) - 2 ; } cout << " Even ▁ Number ▁ = ▁ " << even << ' ' ; cout << " Odd ▁ Number ▁ = ▁ " << odd ; } int main ( ) { int N = 2 , B = 5 ; findNumbers ( N , B ) ; return 0 ; }
Minimum divisor of a number to make the number perfect cube | C ++ program to find minimum number which divide n to make it a perfect cube ; Returns the minimum divisor ; Since 2 is only even prime , compute its power seprately . ; If count is not divisible by 3 , it must be removed by dividing n by prime number power . ; If count is not divisible by 3 , it must be removed by dividing n by prime number power . ; if n is a prime number ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMinNumber ( int n ) { int count = 0 , ans = 1 ; while ( n % 2 == 0 ) { count ++ ; n /= 2 ; } if ( count % 3 != 0 ) ans *= pow ( 2 , ( count % 3 ) ) ; for ( int i = 3 ; i <= sqrt ( n ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n /= i ; } if ( count % 3 != 0 ) ans *= pow ( i , ( count % 3 ) ) ; } if ( n > 2 ) ans *= n ; return ans ; } int main ( ) { int n = 128 ; cout << findMinNumber ( n ) << endl ; return 0 ; }
Check whether the number can be made perfect square after adding K | C ++ program to check whether the number can be made perfect square after adding K ; Function to check whether the number can be made perfect square after adding K ; Computing the square root of the number ; Print Yes if the number is a perfect square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void isPerfectSquare ( long long int x ) { long double sr = round ( sqrt ( x ) ) ; if ( sr * sr == x ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int n = 7 , k = 2 ; isPerfectSquare ( n + k ) ; return 0 ; }
Number of times the largest Perfect Cube can be subtracted from N | C ++ implementation of the approach ; Function to return the count of steps ; Variable to store the count of steps ; Iterate while N > 0 ; Get the largest perfect cube and subtract it from N ; Increment steps ; Return the required count ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSteps ( int n ) { int steps = 0 ; while ( n ) { int largest = cbrt ( n ) ; n -= ( largest * largest * largest ) ; steps ++ ; } return steps ; } int main ( ) { int n = 150 ; cout << countSteps ( n ) ; return 0 ; }
Product of all Subsets of a set formed by first N natural numbers | C ++ implementation of the approach ; Function to find the product of all elements in all subsets in natural numbers from 1 to N ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int product ( int N ) { int ans = 1 ; int val = pow ( 2 , N - 1 ) ; for ( int i = 1 ; i <= N ; i ++ ) { ans *= pow ( i , val ) ; } return ans ; } int main ( ) { int N = 2 ; cout << product ( N ) ; return 0 ; }
Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius | C ++ program to find the radii of the three tangent circles of equal radius when the radius of the circumscribed circle is given ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void threetangcircle ( int R ) { cout << " The ▁ radii ▁ of ▁ the ▁ tangent ▁ circles ▁ is ▁ " << 0.4645 * R << endl ; } int main ( ) { int R = 4 ; threetangcircle ( R ) ; return 0 ; }
Number of common tangents between two circles if their centers and radius is given | C ++ program to find the number of common tangents between the two circles ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) { int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ; int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ; if ( distSq == radSumSq ) return 1 ; else if ( distSq > radSumSq ) return -1 ; else return 0 ; } int main ( ) { int x1 = -10 , y1 = 8 ; int x2 = 14 , y2 = -24 ; int r1 = 30 , r2 = 10 ; int t = circle ( x1 , y1 , x2 , y2 , r1 , r2 ) ; if ( t == 1 ) cout << " There ▁ are ▁ 3 ▁ common ▁ tangents " << " ▁ between ▁ the ▁ circles . " ; else if ( t < 0 ) cout << " There ▁ are ▁ 4 ▁ common ▁ tangents " << " ▁ between ▁ the ▁ circles . " ; else cout << " There ▁ are ▁ 2 ▁ common ▁ tangents " << " ▁ between ▁ the ▁ circles . " ; return 0 ; }
Ratio of the distance between the centers of the circles and the point of intersection of two transverse common tangents to the circles | C ++ program to find the ratio of the distance between the centres of the circles and the point of intersection of two transverse common tangents to the circles which do not touch each other ; Function to find the ratio ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int GCD ( int a , int b ) { return ( b != 0 ? GCD ( b , a % b ) : a ) ; } void ratiotang ( int r1 , int r2 ) { cout << " The ▁ ratio ▁ is ▁ " << r1 / GCD ( r1 , r2 ) << " : " << r2 / GCD ( r1 , r2 ) << endl ; } int main ( ) { int r1 = 4 , r2 = 8 ; ratiotang ( r1 , r2 ) ; return 0 ; }
Program to find the number of region in Planar Graph | C ++ implementation of the approach ; Function to return the number of regions in a Planar Graph ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Regions ( int Vertices , int Edges ) { int R = Edges + 2 - Vertices ; return R ; } int main ( ) { int V = 5 , E = 7 ; cout << Regions ( V , E ) ; return 0 ; }
Ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles | C ++ program to find the ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles which do not touch each other ; Function to find the GCD ; Function to find the ratio ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int GCD ( int a , int b ) { return ( b != 0 ? GCD ( b , a % b ) : a ) ; } void ratiotang ( int r1 , int r2 ) { cout << " The ▁ ratio ▁ is ▁ " << r1 / GCD ( r1 , r2 ) << " ▁ : ▁ " << r2 / GCD ( r1 , r2 ) << endl ; } int main ( ) { int r1 = 4 , r2 = 6 ; ratiotang ( r1 , r2 ) ; return 0 ; }
Length of the transverse common tangent between the two non intersecting circles | C ++ program to find the length of the transverse common tangent between two circles which do not touch each other ; Function to find the length of the transverse common tangent ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void lengthOfTangent ( double r1 , double r2 , double d ) { cout << " The ▁ length ▁ of ▁ the ▁ transverse " << " ▁ common ▁ tangent ▁ is ▁ " << sqrt ( pow ( d , 2 ) - pow ( ( r1 + r2 ) , 2 ) ) << endl ; } int main ( ) { double r1 = 4 , r2 = 6 , d = 12 ; lengthOfTangent ( r1 , r2 , d ) ; return 0 ; }
Area of plot remaining at the end | C ++ implementation of the approach ; Function to return the area of the remaining plot ; Continue while plot has positive area and there are persons left ; If length > breadth then subtract breadth from length ; Else subtract length from breadth ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int remainingArea ( int N , int M , int K ) { while ( K -- && N && M ) { if ( N > M ) N = N - M ; else M = M - N ; } if ( N > 0 && M > 0 ) return N * M ; else return 0 ; } int main ( ) { int N = 5 , M = 3 , K = 2 ; cout << remainingArea ( N , M , K ) ; return 0 ; }
Length of the direct common tangent between two externally touching circles | C ++ program to find the length of the direct common tangent between two circles which externally touch each other ; Function to find the length of the direct common tangent ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void lengtang ( double r1 , double r2 ) { cout << " The ▁ length ▁ of ▁ the ▁ " << " direct ▁ common ▁ tangent ▁ is ▁ " << 2 * sqrt ( r1 * r2 ) << endl ; } int main ( ) { double r1 = 5 , r2 = 9 ; lengtang ( r1 , r2 ) ; return 0 ; }
Shortest distance between a point and a circle | C ++ program to find the Shortest distance between a point and a circle ; Function to find the shortest distance ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void dist ( double x1 , double y1 , double x2 , double y2 , double r ) { cout << " The ▁ shortest ▁ distance ▁ " << " between ▁ a ▁ point ▁ and ▁ a ▁ circle ▁ is ▁ " << sqrt ( ( pow ( ( x2 - x1 ) , 2 ) ) + ( pow ( ( y2 - y1 ) , 2 ) ) ) - r << endl ; } int main ( ) { double x1 = 4 , y1 = 6 , x2 = 35 , y2 = 42 , r = 5 ; dist ( x1 , y1 , x2 , y2 , r ) ; return 0 ; }
Distance between two parallel lines | C ++ program find the distance between two parallel lines ; Function to find the distance between parallel lines ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double dist ( double m , double b1 , double b2 ) { double d = fabs ( b2 - b1 ) / ( ( m * m ) - 1 ) ; return d ; } int main ( ) { double m = 2 , b1 = 4 , b2 = 3 ; cout << dist ( m , b1 , b2 ) ; return 0 ; }
Length of the normal from origin on a straight line whose intercepts are given | C ++ implementation of the approach ; Function to find the normal of the straight line ; Length of the normal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float normal ( float m , float n ) { float N = ( fabsf ( m ) * fabsf ( n ) ) / sqrt ( ( fabsf ( m ) * fabsf ( m ) ) + ( fabsf ( n ) * fabsf ( n ) ) ) ; return N ; } int main ( ) { float m = -5 , n = 3 ; cout << normal ( m , n ) ; return 0 ; }
Check if it is possible to create a polygon with given n sides | C ++ implementation of the approach ; Function that returns true if it is possible to form a polygon with the given sides ; Sum stores the sum of all the sides and maxS stores the length of the largest side ; If the length of the largest side is less than the sum of the other remaining sides ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPossible ( int a [ ] , int n ) { int sum = 0 , maxS = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; maxS = max ( a [ i ] , maxS ) ; } if ( ( sum - maxS ) > maxS ) return true ; return false ; } int main ( ) { int a [ ] = { 2 , 3 , 4 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; if ( isPossible ( a , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Find the area of the shaded region formed by the intersection of four semicircles in a square | C ++ implementation of the approach ; Function to return the area of the shaded region ; Area of the square ; Area of the semicircle ; There are 4 semicircles shadedArea = Area of 4 semicircles - Area of square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float findAreaShaded ( float a ) { float sqArea = a * a ; float semiCircleArea = ( 3.14 * ( a * a ) / 8 ) ; float ShadedArea = 4 * semiCircleArea - sqArea ; return ShadedArea ; } int main ( ) { float a = 10 ; cout << findAreaShaded ( a ) ; return 0 ; }
Number of steps required to reach point ( x , y ) from ( 0 , 0 ) using zig | C ++ program to find the number of steps required to reach ( x , y ) from ( 0 , 0 ) following a zig - zag path ; Function to return the required position ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSteps ( int x , int y ) { if ( x < y ) { return x + y + 2 * ( ( y - x ) / 2 ) ; } else { return x + y + 2 * ( ( ( x - y ) + 1 ) / 2 ) ; } } int main ( ) { int x = 4 , y = 3 ; cout << countSteps ( x , y ) ; return 0 ; }
Find whether only two parallel lines contain all coordinates points or not | C ++ implementation of the above approach ; Find if slope is good with only two intercept ; if set of lines have only two distinct intercept ; Function to check if required solution exist ; check the result by processing the slope by starting three points ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isSlopeGood ( double slope , int arr [ ] , int n ) { set < double > setOfLines ; for ( int i = 0 ; i < n ; i ++ ) setOfLines . insert ( arr [ i ] - slope * ( i ) ) ; return setOfLines . size ( ) == 2 ; } bool checkForParallel ( int arr [ ] , int n ) { bool slope1 = isSlopeGood ( arr [ 1 ] - arr [ 0 ] , arr , n ) ; bool slope2 = isSlopeGood ( arr [ 2 ] - arr [ 1 ] , arr , n ) ; bool slope3 = isSlopeGood ( ( arr [ 2 ] - arr [ 0 ] ) / 2 , arr , n ) ; return ( slope1 slope2 slope3 ) ; } int main ( ) { int arr [ ] = { 1 , 6 , 3 , 8 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << ( int ) checkForParallel ( arr , n ) ; return 0 ; }
Check whether the point ( x , y ) lies on a given line | C ++ implementation of the approach ; Function that return true if the given point lies on the given line ; If ( x , y ) satisfies the equation of the line ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool pointIsOnLine ( int m , int c , int x , int y ) { if ( y == ( ( m * x ) + c ) ) return true ; return false ; } int main ( ) { int m = 3 , c = 2 ; int x = 1 , y = 5 ; if ( pointIsOnLine ( m , c , x , y ) ) cout << " Yes " ; else cout << " No " ; }
Find the coordinates of the fourth vertex of a rectangle with given 3 vertices | C ++ implementation of the approach ; Function that return the coordinates of the fourth vertex of the rectangle ; Save the coordinates of the given vertices of the rectangle ; 1 - based indexing ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; pair < int , int > findFourthVertex ( int n , int m , string s [ ] ) { map < int , int > row , col ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( s [ i ] [ j ] == ' * ' ) { row [ i ] ++ ; col [ j ] ++ ; } int x , y ; for ( auto tm : row ) if ( tm . second == 1 ) x = tm . first ; for ( auto tm : col ) if ( tm . second == 1 ) y = tm . first ; return make_pair ( x + 1 , y + 1 ) ; } int main ( ) { string s [ ] = { " * . * " , " * . . " , " . . . " } ; int n = sizeof ( s ) / sizeof ( s [ 0 ] ) ; int m = s [ 0 ] . length ( ) ; auto rs = findFourthVertex ( n , m , s ) ; cout << rs . first << " ▁ " << rs . second ; }
Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse | C ++ Program to find the biggest Reuleaux triangle inscribed within in a square which in turn is inscribed within an ellipse ; Function to find the biggest reuleaux triangle ; length of the axes cannot be negative ; height of the reuleaux triangle ; area of the reuleaux triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float Area ( float a , float b ) { if ( a < 0 && b < 0 ) return -1 ; float h = sqrt ( ( ( pow ( a , 2 ) + pow ( b , 2 ) ) / ( pow ( a , 2 ) * pow ( b , 2 ) ) ) ) ; float A = 0.70477 * pow ( h , 2 ) ; return A ; } int main ( ) { float a = 5 , b = 4 ; cout << Area ( a , b ) << endl ; return 0 ; }
Maximum given sized rectangles that can be cut out of a sheet of paper | CPP implementation of the approach ; Function to return the maximum rectangles possible ; Cut rectangles horizontally if possible ; One rectangle is a single cell ; Total rectangles = total cells ; Cut rectangles vertically if possible ; Return the maximum possible rectangles ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxRectangles ( int L , int B , int l , int b ) { int horizontal = 0 , vertical = 0 ; if ( l <= L && b <= B ) { int columns = B / b ; int rows = L / l ; horizontal = rows * columns ; } if ( l <= B && b <= L ) { int columns = L / b ; int rows = B / l ; vertical = rows * columns ; } return max ( horizontal , vertical ) ; } int main ( ) { int L = 10 , B = 7 , l = 4 , b = 3 ; cout << ( maxRectangles ( L , B , l , b ) ) << endl ; }
Largest right circular cone that can be inscribed within a sphere which is inscribed within a cube | C ++ Program to find the biggest right circular cone that can be inscribed within a right circular cone which in turn is inscribed within a cube ; Function to find the biggest right circular cone ; side cannot be negative ; radius of right circular cone ; height of right circular cone ; volume of right circular cone ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float cone ( float a ) { if ( a < 0 ) return -1 ; float r = ( a * sqrt ( 2 ) ) / 3 ; float h = ( 2 * a ) / 3 ; float V = 3.14 * pow ( r , 2 ) * h ; return V ; } int main ( ) { float a = 5 ; cout << cone ( a ) << endl ; return 0 ; }
Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon | C ++ Program to find the biggest Reuleaux triangle inscribed within in a square which in turn is inscribed within a hexagon ; Function to find the biggest reuleaux triangle ; side cannot be negative ; height of the reuleaux triangle ; area of the reuleaux triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float Area ( float a ) { if ( a < 0 ) return -1 ; float h = 1.268 * a ; float A = 0.70477 * pow ( h , 2 ) ; return A ; } int main ( ) { float a = 5 ; cout << Area ( a ) << endl ; return 0 ; }
Biggest Reuleaux Triangle inscirbed within a square inscribed in a semicircle | C ++ Program to find the biggest Reuleaux triangle inscribed within in a square which in turn is inscribed within a semicircle ; Function to find the biggest reuleaux triangle ; radius cannot be negative ; height of the reuleaux triangle ; area of the reuleaux triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float Area ( float r ) { if ( r < 0 ) return -1 ; float x = ( 2 * r ) / sqrt ( 5 ) ; float A = 0.70477 * pow ( x , 2 ) ; return A ; } int main ( ) { float r = 5 ; cout << Area ( r ) << endl ; return 0 ; }
Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle | C ++ Program to find the biggest Reuleaux triangle inscribed within in a square which in turn is inscribed within an equilateral triangle ; Function to find the biggest reuleaux triangle ; side cannot be negative ; height of the reuleaux triangle ; area of the reuleaux triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float Area ( float a ) { if ( a < 0 ) return -1 ; float x = 0.464 * a ; float A = 0.70477 * pow ( x , 2 ) ; return A ; } int main ( ) { float a = 5 ; cout << Area ( a ) << endl ; return 0 ; }
Program for Area Of Square after N | CPP program to find the area of the square ; Function to calculate area of square after given number of folds ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double areaSquare ( double side , double fold ) { double area = side * side ; return area * 1.0 / pow ( 2 , fold ) ; } int main ( ) { double side = 4 , fold = 2 ; cout << areaSquare ( side , fold ) ; return 0 ; }
Biggest Reuleaux Triangle within a Square which is inscribed within a Circle | C ++ Program to find the biggest Reuleaux triangle inscribed within in a square which in turn is inscribed within a circle ; Function to find the Area of the Reuleaux triangle ; radius cannot be negative ; Area of the Reuleaux triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float ReuleauxArea ( float r ) { if ( r < 0 ) return -1 ; float A = 0.70477 * 2 * pow ( r , 2 ) ; return A ; } int main ( ) { float r = 6 ; cout << ReuleauxArea ( r ) << endl ; return 0 ; }
Largest right circular cylinder that can be inscribed within a cone which is in turn inscribed within a cube | C ++ Program to find the biggest right circular cylinder that can be inscribed within a right circular cone which in turn is inscribed within a cube ; Function to find the biggest right circular cylinder ; side 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 a ) { if ( a < 0 ) return -1 ; float r = ( 2 * a * sqrt ( 2 ) ) / 3 ; float h = ( 2 * a ) / 3 ; float V = 3.14 * pow ( r , 2 ) * h ; return V ; } int main ( ) { float a = 5 ; cout << cyl ( a ) << endl ; return 0 ; }
Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle | C ++ Program to find the biggest Reuleaux triangle inscribed within in a square which in turn is inscribed within a circle ; Function to find the biggest reuleaux triangle ; the height or base or hypotenuse cannot be negative ; height of the reuleaux triangle ; area of the reuleaux triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float Area ( float l , float b , float h ) { if ( l < 0 b < 0 h < 0 ) return -1 ; float x = ( l * b ) / ( l + b ) ; float A = 0.70477 * pow ( x , 2 ) ; return A ; } int main ( ) { float l = 5 , b = 12 , h = 13 ; cout << Area ( l , b , h ) << endl ; return 0 ; }
Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle | C ++ program to find the side of the largest square that can be inscribed within the hexagon which in return is incsribed within an equilateral triangle ; Function to find the side of the square ; Side cannot be negative ; side of the square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float squareSide ( float a ) { if ( a < 0 ) return -1 ; float x = 0.423 * a ; return x ; } int main ( ) { float a = 8 ; cout << squareSide ( a ) << endl ; return 0 ; }
Check if it is possible to draw a straight line with the given direction cosines | C ++ implementation of the approach ; Function that returns true if a straight line is possible ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPossible ( float x , float y , float z ) { float a = x * x + y * y + z * z ; if ( ceil ( a ) == 1 && floor ( a ) == 1 ) return true ; return false ; } int main ( ) { float l = 0.70710678 , m = 0.5 , n = 0.5 ; if ( isPossible ( l , m , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Length of Diagonal of a n | C ++ Program to find the diagonal of a regular polygon with given side length ; Function to find the diagonal of a regular polygon ; Side and side length cannot be negative ; diagonal degree converted to radians ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float polydiagonal ( float n , float a ) { if ( a < 0 && n < 0 ) return -1 ; return 2 * a * sin ( ( ( ( n - 2 ) * 180 ) / ( 2 * n ) ) * 3.14159 / 180 ) ; } int main ( ) { float a = 9 , n = 10 ; cout << polydiagonal ( n , a ) << endl ; return 0 ; }
Diagonal of a Regular Decagon | C ++ program to find the diagonal of a regular decagon ; Function to return the diagonal of a regular decagon ; Side cannot be negative ; Length of the diagonal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float decdiagonal ( float a ) { if ( a < 0 ) return -1 ; float d = 1.902 * a ; return d ; } int main ( ) { float a = 9 ; cout << decdiagonal ( a ) << endl ; return 0 ; }