codeparrot/xlcost-text-to-code huggingface dataset:
Equation of a straight line with perpendicular distance D from origin and an angle A between the perpendicular from origin and x | C ++ program for the approach ; Function to find equation of a line whose distance from origin and angle made by the perpendicular from origin with x - axis is given ; Convert angle from degree to radian ; Handle the special case ; Calculate the sin and cos of angle ; Print the equation of the line ; Driver Code ; Given Input ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findLine ( int distance , float degree ) { float x = degree * 3.14159 / 180 ; if ( degree > 90 ) { cout << " Not ▁ Possible " ; return ; } float result_1 = sin ( x ) ; float result_2 = cos ( x ) ; cout << fixed << setprecision ( 2 ) << result_2 << " x ▁ + " << result_1 << " y ▁ = ▁ " << distance ; } int main ( ) { int D = 10 ; float A = 30 ; findLine ( D , A ) ; return 0 ; }
Count number of coordinates from an array satisfying the given conditions | C ++ program for the above approach ; Function to count the number of coordinates from a given set that satisfies the given conditions ; Stores the count of central points ; Store the count of each x and y coordinates ; Find all possible pairs ; Initialize variables c1 , c2 , c3 , c4 to define the status of conditions ; Stores value of each point ; Check the conditions for each point by generating all possible pairs ; If arr [ j ] [ 0 ] > x and arr [ j ] [ 1 ] == y ; If arr [ j ] [ 0 ] < x and arr [ j ] [ 1 ] = = y ; If arr [ j ] [ 1 ] > y and arr [ j ] [ 0 ] == x ; If arr [ j ] [ 1 ] < y and arr [ j ] [ 0 ] = = x ; If all conditions satisfy then point is central point ; Increment the count by 1 ; Return the count ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int centralPoints ( int arr [ ] [ 2 ] , int N ) { int count = 0 ; int c1 , c2 , c3 , c4 ; for ( int i = 0 ; i < N ; i ++ ) { c1 = 0 , c2 = 0 , c3 = 0 ; c4 = 0 ; int x = arr [ i ] [ 0 ] ; int y = arr [ i ] [ 1 ] ; for ( int j = 0 ; j < N ; j ++ ) { if ( arr [ j ] [ 0 ] > x && arr [ j ] [ 1 ] == y ) { c1 = 1 ; } if ( arr [ j ] [ 1 ] > y && arr [ j ] [ 0 ] == x ) { c2 = 1 ; } if ( arr [ j ] [ 0 ] < x && arr [ j ] [ 1 ] == y ) { c3 = 1 ; } if ( arr [ j ] [ 1 ] < y && arr [ j ] [ 0 ] == x ) { c4 = 1 ; } } if ( c1 + c2 + c3 + c4 == 4 ) { count ++ ; } } return count ; } int main ( ) { int arr [ 4 ] [ 2 ] = { { 1 , 0 } , { 2 , 0 } , { 1 , 1 } , { 1 , -1 } } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << centralPoints ( arr , N ) ; return 0 ; }
Displacement from origin after N moves of given distances in specified directions | C ++ program for the above approach ; Function to find the displacement from the origin and direction after performing the given set of moves ; Stores the distances travelled in the directions North , South , East , and West respectively ; Store the initial position of robot ; Traverse the array B [ ] ; If the current direction is North ; If the current direction is South ; If the current direction is East ; If the current direction is West ; Stores the total vertical displacement ; Stores the total horizontal displacement ; Find the displacement ; Print the displacement and direction after N moves ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void finalPosition ( char a [ ] , int b [ ] , int M ) { int n = 0 , s = 0 , e = 0 , w = 0 ; char p = ' N ' ; for ( int i = 0 ; i < M ; i ++ ) { if ( p == ' N ' ) { if ( a [ i ] == ' U ' ) { p = ' N ' ; n = n + b [ i ] ; } else if ( a [ i ] == ' D ' ) { p = ' S ' ; s = s + b [ i ] ; } else if ( a [ i ] == ' R ' ) { p = ' E ' ; e = e + b [ i ] ; } else if ( a [ i ] == ' L ' ) { p = ' W ' ; w = w + b [ i ] ; } } else if ( p == ' S ' ) { if ( a [ i ] == ' U ' ) { p = ' S ' ; s = s + b [ i ] ; } else if ( a [ i ] == ' D ' ) { p = ' N ' ; n = n + b [ i ] ; } else if ( a [ i ] == ' R ' ) { p = ' W ' ; w = w + b [ i ] ; } else if ( a [ i ] == ' L ' ) { p = ' E ' ; e = e + b [ i ] ; } } else if ( p == ' E ' ) { if ( a [ i ] == ' U ' ) { p = ' E ' ; e = e + b [ i ] ; } else if ( a [ i ] == ' D ' ) { p = ' W ' ; w = w + b [ i ] ; } else if ( a [ i ] == ' R ' ) { p = ' S ' ; s = s + b [ i ] ; } else if ( a [ i ] == ' L ' ) { p = ' N ' ; n = n + b [ i ] ; } } else if ( p == ' W ' ) { if ( a [ i ] == ' U ' ) { p = ' W ' ; w = w + b [ i ] ; } else if ( a [ i ] == ' D ' ) { p = ' E ' ; e = e + b [ i ] ; } else if ( a [ i ] == ' R ' ) { p = ' N ' ; n = n + b [ i ] ; } else if ( a [ i ] == ' L ' ) { p = ' S ' ; s = s + b [ i ] ; } } } int ver_disp = n - s ; int hor_disp = e - w ; int displacement = floor ( sqrt ( ( ver_disp * ver_disp ) + ( hor_disp * hor_disp ) ) ) ; cout << displacement << " ▁ " << p ; } int main ( ) { char A [ ] = { ' U ' , ' R ' , ' R ' , ' R ' , ' R ' } ; int B [ ] = { 1 , 1 , 1 , 1 , 0 } ; int N = sizeof ( A ) / sizeof ( B [ 0 ] ) ; finalPosition ( A , B , N ) ; return 0 ; }
Program to find Length of Latus Rectum of an Ellipse | C ++ program for the above approach ; Function to calculate the length of the latus rectum of an ellipse ; Length of major axis ; Length of minor axis ; Length of the latus rectum ; Driver Code ; Given lengths of semi - major and semi - minor axis ; Function call to calculate length of the latus rectum of a ellipse
#include <iostream> NEW_LINE using namespace std ; double lengthOfLatusRectum ( double A , double B ) { double major = 2.0 * A ; double minor = 2.0 * B ; double latus_rectum = ( minor * minor ) / major ; return latus_rectum ; } int main ( ) { double A = 3.0 , B = 2.0 ; cout << lengthOfLatusRectum ( A , B ) ; return 0 ; }
Program to find slant height of cone and pyramid | C ++ program for the above approach ; Function to calculate slant height of a cone ; Store the slant height of cone ; Print the result ; Function to find the slant height of a pyramid ; Store the slant height of pyramid ; Print the result ; Driver Code ; Dimensions of Cone ; Function Call for slant height of Cone ; Dimensions of Pyramid ; Function to calculate slant height of a pyramid
#include <bits/stdc++.h> NEW_LINE using namespace std ; void coneSlantHeight ( double cone_h , double cone_r ) { double slant_height_cone = sqrt ( pow ( cone_h , 2 ) + pow ( cone_r , 2 ) ) ; cout << " Slant ▁ height ▁ of ▁ cone ▁ is : ▁ " << slant_height_cone << ' ' ; } void pyramidSlantHeight ( double pyramid_h , double pyramid_s ) { double slant_height_pyramid = sqrt ( pow ( pyramid_s / 2 , 2 ) + pow ( pyramid_h , 2 ) ) ; cout << " Slant ▁ height ▁ of ▁ pyramid ▁ is : ▁ " << slant_height_pyramid << ' ' ; } int main ( ) { double H1 = 4.5 , R = 6 ; coneSlantHeight ( H1 , R ) ; double H2 = 4 , S = 4.8 ; pyramidSlantHeight ( H2 , S ) ; return 0 ; }
Program to find the length of Latus Rectum of a Parabola | C ++ program for the above approach ; Function to calculate distance between two points ; Calculating distance ; Function to calculate length of the latus rectum of a parabola ; Stores the co - ordinates of the vertex of the parabola ; Stores the co - ordinates of the focus of parabola ; Print the distance between focus and vertex ; Driver Code ; Given a , b & c ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; float distance ( float x1 , float y1 , float x2 , float y2 ) { return sqrt ( ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) ) ; } float lengthOfLatusRectum ( float a , float b , float c ) { pair < float , float > vertex = { ( - b / ( 2 * a ) ) , ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) } ; pair < float , float > focus = { ( - b / ( 2 * a ) ) , ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) } ; cout << 4 * distance ( focus . first , focus . second , vertex . first , vertex . second ) ; } int main ( ) { float a = 3 , b = 5 , c = 1 ; lengthOfLatusRectum ( a , b , c ) ; return 0 ; }
Program to convert polar co | C ++ program for the above approach ; Function to convert degree to radian ; Function to convert the polar coordinate to cartesian ; Convert degerees to radian ; Applying the formula : x = rcos ( theata ) , y = rsin ( theta ) ; Print cartesian coordinates ; Driver Code ; Given polar coordinates ; Function to convert polar coordinates to equivalent cartesian coordinates
#include <bits/stdc++.h> NEW_LINE using namespace std ; double ConvertDegToRad ( double degree ) { double pi = 3.14159 ; return ( degree * ( pi / 180.0 ) ) ; } void ConvertToCartesian ( pair < double , double > polar ) { polar . second = ConvertDegToRad ( polar . second ) ; pair < double , double > cartesian = { polar . first * cos ( polar . second ) , polar . first * sin ( polar . second ) } ; printf ( " % 0.3f , ▁ % 0.3f " , cartesian . first , cartesian . second ) ; } int main ( ) { pair < double , double > polar = { 1.4142 , 45 } ; ConvertToCartesian ( polar ) ; return 0 ; }
Distance between orthocenter and circumcenter of a right | C ++ program for the above approach ; Function to calculate Euclidean distance between the points p1 and p2 ; Stores x coordinates of both points ; Stores y coordinates of both points ; Return the Euclid distance using distance formula ; Function to find orthocenter of the right angled triangle ; Find the length of the three sides ; Orthocenter will be the vertex opposite to the largest side ; Function to find the circumcenter of right angle triangle ; Circumcenter will be located at center of hypotenuse ; If AB is the hypotenuse ; If BC is the hypotenuse ; If AC is the hypotenuse ; Function to find distance between orthocenter and circumcenter ; Find circumcenter ; Find orthocenter ; Find the distance between the orthocenter and circumcenter ; Print distance between orthocenter and circumcenter ; Driver Code ; Given coordinates A , B , and C ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; double distance ( pair < double , double > p1 , pair < double , double > p2 ) { double x1 = p1 . first , x2 = p2 . first ; double y1 = p1 . second , y2 = p2 . second ; return sqrt ( pow ( x2 - x1 , 2 ) + pow ( y2 - y1 , 2 ) * 1.0 ) ; } pair < double , double > find_orthocenter ( pair < double , double > A , pair < double , double > B , pair < double , double > C ) { double AB = distance ( A , B ) ; double BC = distance ( B , C ) ; double CA = distance ( C , A ) ; if ( AB > BC && AB > CA ) return C ; if ( BC > AB && BC > CA ) return A ; return B ; } pair < double , double > find_circumcenter ( pair < double , double > A , pair < double , double > B , pair < double , double > C ) { double AB = distance ( A , B ) ; double BC = distance ( B , C ) ; double CA = distance ( C , A ) ; if ( AB > BC && AB > CA ) return { ( A . first + B . first ) / 2 , ( A . second + B . second ) / 2 } ; if ( BC > AB && BC > CA ) return { ( B . first + C . first ) / 2 , ( B . second + C . second ) / 2 } ; return { ( C . first + A . first ) / 2 , ( C . second + A . second ) / 2 } ; } void findDistance ( pair < double , double > A , pair < double , double > B , pair < double , double > C ) { pair < double , double > circumcenter = find_circumcenter ( A , B , C ) ; pair < double , double > orthocenter = find_orthocenter ( A , B , C ) ; double distance_between = distance ( circumcenter , orthocenter ) ; cout << distance_between << endl ; } int main ( ) { pair < double , double > A , B , C ; A = { 0.0 , 0.0 } ; B = { 6.0 , 0.0 } ; C = { 0.0 , 8.0 } ; findDistance ( A , B , C ) ; return 0 ; }
Generate all integral points lying inside a rectangle | C ++ program to implement the above approach ; Function to generate coordinates lying within the rectangle ; Store all possible coordinates that lie within the rectangle ; Stores the number of possible coordinates that lie within the rectangle ; Use current time as seed for random generator ; Generate all possible coordinates ; Generate all possible X - coordinates ; Generate all possible Y - coordinates ; If coordinates ( X , Y ) has not been generated already ; Insert the coordinates ( X , Y ) ; Print the coordinates ; Driver Code ; Rectangle dimensions
#include <bits/stdc++.h> NEW_LINE using namespace std ; void generatePoints ( int L , int W ) { set < pair < int , int > > hash ; int total = ( L * W ) ; srand ( time ( 0 ) ) ; while ( total -- ) { int X = rand ( ) % L ; int Y = rand ( ) % W ; while ( hash . count ( { X , Y } ) ) { X = rand ( ) % L ; Y = rand ( ) % W ; } hash . insert ( { X , Y } ) ; } for ( auto points : hash ) { cout << " ( " << points . first << " , ▁ " << points . second << " ) ▁ " ; } } int main ( ) { int L = 3 , W = 2 ; generatePoints ( L , W ) ; }
Count triangles required to form a House of Cards of height N | C ++ implementation of the above approach ; Function to find the number of triangles ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int noOfTriangles ( int n ) { return floor ( n * ( n + 2 ) * ( 2 * n + 1 ) / 8 ) ; } int main ( ) { int n = 3 ; cout << noOfTriangles ( n ) << endl ; return 0 ; }
Check if N contains all digits as K in base B | C ++ implementation of the approach ; Function to print the number of digits ; Calculate log using base change property and then take its floor and then add 1 ; Return the output ; Function that returns true if n contains all one 's in base b ; Calculate the sum ; Driver code ; Given number N ; Given base B ; Given digit K ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findNumberOfDigits ( int n , int base ) { int dig = ( floor ( log ( n ) / log ( base ) ) + 1 ) ; return ( dig ) ; } int isAllKs ( int n , int b , int k ) { int len = findNumberOfDigits ( n , b ) ; int sum = k * ( 1 - pow ( b , len ) ) / ( 1 - b ) ; if ( sum == n ) { return ( sum ) ; } } int main ( ) { int N = 13 ; int B = 3 ; int K = 1 ; if ( isAllKs ( N , B , K ) ) { cout << " Yes " ; } else { cout << " No " ; } }
Check if a right | C ++ program to implement the above approach ; Function to check if right - angled triangle can be formed by the given coordinates ; Calculate the sides ; Check Pythagoras Formula ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkRightAngled ( int X1 , int Y1 , int X2 , int Y2 , int X3 , int Y3 ) { int A = ( int ) pow ( ( X2 - X1 ) , 2 ) + ( int ) pow ( ( Y2 - Y1 ) , 2 ) ; int B = ( int ) pow ( ( X3 - X2 ) , 2 ) + ( int ) pow ( ( Y3 - Y2 ) , 2 ) ; int C = ( int ) pow ( ( X3 - X1 ) , 2 ) + ( int ) pow ( ( Y3 - Y1 ) , 2 ) ; if ( ( A > 0 and B > 0 and C > 0 ) and ( A == ( B + C ) or B == ( A + C ) or C == ( A + B ) ) ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int X1 = 0 , Y1 = 2 ; int X2 = 0 , Y2 = 14 ; int X3 = 9 , Y3 = 2 ; checkRightAngled ( X1 , Y1 , X2 , Y2 , X3 , Y3 ) ; return 0 ; }
Count of intersections of M line segments with N vertical lines in XY plane | C ++ implementation for the above approach . ; Function to create prefix sum array ; Initialize the prefix array to remove garbage values ; Marking the occurences of vertical lines ; x is the value after Index mapping ; Creating the prefix array ; Function returns the count of total intersection ; ans is the number of points of intersection of the line segments with the vertical lines ; Index mapping ; We don 't consider a vertical  line segment because even if  it falls on a verticale line  then it just touches it and  not intersects. ; We have assumed that x1 will be left and x2 right but if not then we just swap them ; Driver code ; N is the number of vertical lines M is the number of line segments ; Format : x1 , y1 , x2 , y1 ; First create the prefix array ; Print the total number of intersections
#include <bits/stdc++.h> NEW_LINE using namespace std ; void createPrefixArray ( int n , int arr [ ] , int prefSize , int pref [ ] ) { for ( int i = 0 ; i < prefSize ; i ++ ) { pref [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { int x = arr [ i ] + 1000000 ; pref [ x ] ++ ; } for ( int i = 1 ; i < prefSize ; i ++ ) { pref [ i ] += pref [ i - 1 ] ; } } int pointsOfIntersection ( int m , int segments [ ] [ 4 ] , int size , int pref [ ] ) { int ans = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int x1 = segments [ i ] [ 0 ] ; int x2 = segments [ i ] [ 2 ] ; x1 = x1 + 1000000 ; x2 = x2 + 1000000 ; if ( x1 != x2 ) { if ( x1 > x2 ) { swap ( x1 , x2 ) ; } int Occ_Till_Right = pref [ x2 - 1 ] ; int Occ_Till_Left = pref [ x1 ] ; ans = ans + ( Occ_Till_Right - Occ_Till_Left ) ; } } return ans ; } int main ( ) { int N = 4 ; int M = 8 ; int size = 2000000 + 2 ; int pref [ size ] ; int lines [ N ] = { -5 , -3 , 2 , 3 } ; int segments [ M ] [ 4 ] = { { -2 , 5 , 5 , -6 } , { -5 , -2 , -3 , -5 } , { -2 , 3 , -6 , 1 } , { -1 , -3 , 4 , 2 } , { 2 , 5 , 2 , 1 } , { 4 , 5 , 4 , -5 } , { -2 , -4 , 5 , 3 } , { 1 , 2 , -2 , 1 } } ; createPrefixArray ( N , lines , size , pref ) ; cout << pointsOfIntersection ( M , segments , size , pref ) << endl ; return 0 ; }
Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively | C ++ Program to count number of rectangles formed by N lines parallel to X axis M lines parallel to Y axis ; Function to calculate number of rectangles ; Total number of ways to select two lines parallel to X axis ; Total number of ways to select two lines parallel to Y axis ; Total number of rectangles ; Driver Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int count_rectangles ( int N , int M ) { int p_x = ( N * ( N - 1 ) ) / 2 ; int p_y = ( M * ( M - 1 ) ) / 2 ; return p_x * p_y ; } int main ( ) { int N = 3 ; int M = 6 ; cout << count_rectangles ( N , M ) ; }
Angle between a Pair of Lines in 3D | C ++ program for the above approach ; Function to find the angle between the two lines ; Find direction ratio of line AB ; Find direction ratio of line BC ; Find the dotProduct of lines AB & BC ; Find magnitude of line AB and BC ; Find the cosine of the angle formed by line AB and BC ; Find angle in radian ; Print the angle ; Driver Code ; Given coordinates Points A ; Points B ; Points C ; Function Call
#include " bits / stdc + + . h " NEW_LINE #define PI  3.14 NEW_LINE using namespace std ; void calculateAngle ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 , int x3 , int y3 , int z3 ) { int ABx = x1 - x2 ; int ABy = y1 - y2 ; int ABz = z1 - z2 ; int BCx = x3 - x2 ; int BCy = y3 - y2 ; int BCz = z3 - z2 ; double dotProduct = ABx * BCx + ABy * BCy + ABz * BCz ; double magnitudeAB = ABx * ABx + ABy * ABy + ABz * ABz ; double magnitudeBC = BCx * BCx + BCy * BCy + BCz * BCz ; double angle = dotProduct ; angle /= sqrt ( magnitudeAB * magnitudeBC ) ; angle = ( angle * 180 ) / PI ; cout << abs ( angle ) << endl ; } int main ( ) { int x1 = 1 , y1 = 3 , z1 = 3 ; int x2 = 3 , y2 = 4 , z2 = 5 ; int x3 = 5 , y3 = 6 , z3 = 9 ; calculateAngle ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) ; return 0 ; }
Distance between end points of Hour and minute hand at given time | C ++ implementation to find the distance between the end points of the hour and minute hand ; Function to find the angle between Hour hand and minute hand ; Validate the input ; Calculate the angles moved by hour and minute hands with reference to 12 : 00 ; Find the difference between two angles ; Return the smaller angle of two possible angles ; Function to calculate cos value of angle c ; Converting degrees to radian ; Maps the sum along the series ; Holds the actual value of sin ( n ) ; Function to distance between the endpoints of the hour and minute hand ; Driver Code ; Time ; Length of hour hand ; Length of minute hand ; calling Function for finding angle between hour hand and minute hand ; Function for finding distance between end points of minute hand and hour hand
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calcAngle ( double h , double m ) { if ( h < 0 m < 0 h > 12 m > 60 ) printf ( " Wrong ▁ input " ) ; if ( h == 12 ) h = 0 ; if ( m == 60 ) m = 0 ; int hour_angle = 0.5 * ( h * 60 + m ) ; int minute_angle = 6 * m ; int angle = abs ( hour_angle - minute_angle ) ; angle = min ( 360 - angle , angle ) ; return angle ; } float cal_cos ( float n ) { float accuracy = 0.0001 , x1 , denominator , cosx , cosval ; n = n * ( 3.142 / 180.0 ) ; x1 = 1 ; cosx = x1 ; cosval = cos ( n ) ; int i = 1 ; do { denominator = 2 * i * ( 2 * i - 1 ) ; x1 = - x1 * n * n / denominator ; cosx = cosx + x1 ; i = i + 1 ; } while ( accuracy <= fabs ( cosval - cosx ) ) ; return cosx ; } float distanceEndpoints ( int a , int b , float c ) { float angle = cal_cos ( c ) ; return sqrt ( ( a * a ) + ( b * b ) - 2 * a * b * angle ) ; } int main ( ) { int hour = 3 ; int min = 30 ; int hourHand = 3 ; int minHand = 4 ; double angle = calcAngle ( hour , min ) ; float distance = distanceEndpoints ( minHand , hourHand , angle ) ; cout << distance ; return 0 ; }
Pentadecagonal Number | C ++ program to find Nth Pentadecagonal number ; Function to find N - th Pentadecagonal number ; Formula to calculate nth Pentadecagonal number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Pentadecagonal_num ( int n ) { return ( 13 * n * n - 11 * n ) / 2 ; } int main ( ) { int n = 3 ; cout << Pentadecagonal_num ( n ) << endl ; n = 10 ; cout << Pentadecagonal_num ( n ) << endl ; return 0 ; }
Octadecagonal Number | C ++ program to find Nth Octadecagonal number ; Function to find N - th Octadecagonal number ; Formula to calculate nth Octadecagonal number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Octadecagonal_num ( int n ) { return ( 16 * n * n - 14 * n ) / 2 ; } int main ( ) { int n = 3 ; cout << Octadecagonal_num ( n ) << endl ; n = 10 ; cout << Octadecagonal_num ( n ) << endl ; return 0 ; }
Icositrigonal Number | C ++ program to find nth Icositrigonal number ; Function to find N - th Icositrigonal number ; Formula to calculate nth Icositrigonal number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Icositrigonal_num ( int n ) { return ( 21 * n * n - 19 * n ) / 2 ; } int main ( ) { int n = 3 ; cout << Icositrigonal_num ( n ) << endl ; n = 10 ; cout << Icositrigonal_num ( n ) ; return 0 ; }
Find the percentage change in the area of a Rectangle | CPP implementation to find the percentage ; Function to calculate percentage change in area of rectangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculate_change ( int length , int breadth ) { int change = 0 ; change = length + breadth + ( ( length * breadth ) / 100 ) ; return change ; } int main ( ) { int cL = 20 ; int cB = -10 ; int cA = calculate_change ( cL , cB ) ; printf ( " % d " , cA ) ; return 0 ; }
Minimum number of Circular obstacles required to obstruct the path in a Grid | C ++ program to find the minimum number of obstacles required ; Function to find the minimum number of obstacles required ; Find the minimum range required to put obstacles ; Sorting the radius ; If val is less than zero then we have find the number of obstacles required ; Driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int solve ( int n , int m , int obstacles , double range [ ] ) { double val = min ( n , m ) ; sort ( range , range + obstacles ) ; int c = 1 ; for ( int i = obstacles - 1 ; i >= 0 ; i -- ) { range [ i ] = 2 * range [ i ] ; val -= range [ i ] ; if ( val <= 0 ) { return c ; } else { c ++ ; } } if ( val > 0 ) { return -1 ; } } int main ( ) { int n = 4 , m = 5 , obstacles = 3 ; double range [ ] = { 1.0 , 1.25 , 1.15 } ; cout << solve ( n , m , obstacles , range ) << " STRNEWLINE " ; return 0 ; }
Program to calculate area of a rhombus whose one side and diagonal are given | C ++ program to calculate the area of a rhombus whose one side and one diagonal is given ; function to calculate the area of the rhombus ; Second diagonal ; area of rhombus ; return the area ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double area ( double d1 , double a ) { double d2 = sqrt ( 4 * ( a * a ) - d1 * d1 ) ; double area = 0.5 * d1 * d2 ; return area ; } int main ( ) { double d = 7.07 ; double a = 5 ; printf ( " % 0.8f " , area ( d , a ) ) ; }