codeparrot/xlcost-text-to-code huggingface dataset:
Check if it is possible to move from ( a , 0 ) to ( b , 0 ) with given jumps | CPP program to move form ( a , 0 ) to ( b , 0 ) with given jumps ; Function to check if it is possible ; Driver code ; function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool Move ( int a , int x , int b ) { if ( ( ( ( b - a ) % x == 0 ) || ( ( b - a - 1 ) % x == 0 ) && a + 1 != b ) && b >= a ) return true ; return false ; } int main ( ) { int a = 3 , x = 2 , b = 7 ; if ( Move ( a , x , b ) ) cout << " Yes " ; else cout << " No " ; }
Area of a triangle inscribed in a rectangle which is inscribed in an ellipse | C ++ Program to find the area of the triangle inscribed within the rectangle which in turn is inscribed in an ellipse ; Function to find the area of the triangle ; length of a and b cannot be negative ; area of the triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float area ( float a , float b ) { if ( a < 0 b < 0 ) return -1 ; float A = a * b ; return A ; } int main ( ) { float a = 5 , b = 2 ; cout << area ( a , b ) << endl ; return 0 ; }
Circumradius of the rectangle | C ++ Program to find the radius of the circumcircle of the given rectangle ; Function to find the radius of the circumcircle ; the sides cannot be negative ; Radius of the circumcircle ; Return the radius ; Driver code ; Get the sides of the triangle ; Find the radius of the circumcircle
#include <bits/stdc++.h> NEW_LINE using namespace std ; float findRadiusOfcircumcircle ( float l , float b ) { if ( l < 0 b < 0 ) return -1 ; float radius = sqrt ( pow ( l , 2 ) + pow ( b , 2 ) ) / 2 ; return radius ; } int main ( ) { float l = 4 , b = 3 ; cout << findRadiusOfcircumcircle ( l , b ) << endl ; return 0 ; }
Area of the circumcircle of any triangles with sides given | C ++ Program to find the area the circumcircle of the given triangle ; Function to find the area of the circumcircle ; the sides cannot be negative ; semi - perimeter of the circle ; area of triangle ; area of the circle ; Driver code ; Get the sides of the triangle ; Find and print the area of the circumcircle
#include <bits/stdc++.h> NEW_LINE using namespace std ; float circlearea ( float a , float b , float c ) { if ( a < 0 b < 0 c < 0 ) return -1 ; float p = ( a + b + c ) / 2 ; float At = sqrt ( p * ( p - a ) * ( p - b ) * ( p - c ) ) ; float A = 3.14 * pow ( ( ( a * b * c ) / ( 4 * At ) ) , 2 ) ; return A ; } int main ( ) { float a = 4 , b = 5 , c = 3 ; cout << circlearea ( a , b , c ) << endl ; return 0 ; }
Find the altitude and area of an isosceles triangle | CPP program to find the Altitude Area of an isosceles triangle ; function to find the altitude ; return altitude ; function to find the area ; return area ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float altitude ( float a , float b ) { return sqrt ( pow ( a , 2 ) - ( pow ( b , 2 ) / 4 ) ) ; } float area ( float b , float h ) { return ( 1 * b * h ) / 2 ; } int main ( ) { float a = 2 , b = 3 ; float h = altitude ( a , b ) ; cout << setprecision ( 3 ) ; cout << " Altitude = ▁ " << h << " , ▁ " ; cout << " Area = ▁ " << area ( b , h ) ; return 0 ; }
Program to find the surface area of the square pyramid | CPP program to find the surface area Of Square pyramid ; function to find the surface area ; Driver program ; surface area of the square pyramid
#include <bits/stdc++.h> NEW_LINE using namespace std ; int surfaceArea ( int b , int s ) { return 2 * b * s + pow ( b , 2 ) ; } int main ( ) { int b = 3 , s = 4 ; cout << surfaceArea ( b , s ) << endl ; return 0 ; }
Area of largest triangle that can be inscribed within a rectangle | C ++ Program to find the biggest triangle which can be inscribed within the rectangle ; Function to find the area of the triangle ; a and b cannot be negative ; area of the triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float trianglearea ( float l , float b ) { if ( l < 0 b < 0 ) return -1 ; float area = ( l * b ) / 2 ; return area ; } int main ( ) { float l = 5 , b = 4 ; cout << trianglearea ( l , b ) << endl ; return 0 ; }
Check if any square ( with one colored cell ) can be divided into two equal parts | C ++ program to illustrate the above problem ; function to check if it 's possible to divide the square in two equal parts ; if the painted square is linked anyway to the center of the square then it 's not possible ; else yes it 's possible ; Driver code ; initialize the size of the square ; initialize the dimension of the painted square
#include <bits/stdc++.h> NEW_LINE using namespace std ; void halfsquare ( int n , int x , int y ) { int half = n / 2 ; if ( ( half == x half == x - 1 ) && ( half == y half == y - 1 ) ) cout << " NO " << endl ; else cout << " YES " << endl ; } int main ( ) { int n = 100 ; int x = 51 , y = 100 ; halfsquare ( n , x , y ) ; return 0 ; }
Check if it is possible to reach vector B by rotating vector A and adding vector C to it | C ++ program to Check if it is possible to reach vector B by Rotating vector A and adding vector C to it any number of times ; function to check if vector B is possible from vector A ; if d = 0 , then you need to add nothing to vector A ; for all four quadrants ; Driver code ; initialize all three vector coordinates
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long NEW_LINE ll check ( ll a , ll b , ll p , ll q ) { ll d = p * p + q * q ; if ( d == 0 ) return a == 0 && b == 0 ; else return ( a * p + b * q ) % d == 0 && ( b * p - a * q ) % d == 0 ; } bool check ( int a , int b , int x , int y , int p , int q ) { if ( check ( a - x , b - y , p , q ) || check ( a + x , b + y , p , q ) || check ( a - y , b + x , p , q ) || check ( a + y , b - x , p , q ) ) return true ; else return false ; } int main ( ) { int a = -4 , b = -2 ; int x = 0 , y = 0 ; int p = -2 , q = -1 ; if ( check ( a , b , x , y , p , q ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Largest triangle that can be inscribed in an ellipse | C ++ Program to find the biggest triangle which can be inscribed within the ellipse ; Function to find the area of the triangle ; a and b cannot be negative ; area of the triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float trianglearea ( float a , float b ) { if ( a < 0 b < 0 ) return -1 ; float area = ( 3 * sqrt ( 3 ) * pow ( a , 2 ) ) / ( 4 * b ) ; return area ; } int main ( ) { float a = 4 , b = 2 ; cout << trianglearea ( a , b ) << endl ; return 0 ; }
Area of the Largest square that can be inscribed in an ellipse | C ++ Program to find the biggest square which can be inscribed within the ellipse ; Function to find the area of the square ; a and b cannot be negative ; area of the square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float squarearea ( float a , float b ) { if ( a < 0 b < 0 ) return -1 ; float area = 4 * ( ( pow ( a , 2 ) + pow ( b , 2 ) ) / ( pow ( a , 2 ) * pow ( b , 2 ) ) ) ; return area ; } int main ( ) { float a = 4 , b = 2 ; cout << squarearea ( a , b ) << endl ; return 0 ; }
Largest triangle that can be inscribed in a semicircle | C ++ Program to find the biggest triangle which can be inscribed within the semicircle ; Function to find the area of the triangle ; the radius cannot be negative ; area of the triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float trianglearea ( float r ) { if ( r < 0 ) return -1 ; return r * r ; } int main ( ) { float r = 5 ; cout << trianglearea ( r ) << endl ; return 0 ; }
Largest square that can be inscribed in a semicircle | C ++ Program to find the biggest square which can be inscribed within the semicircle ; Function to find the area of the square ; the radius cannot be negative ; area of the square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float squarearea ( float r ) { if ( r < 0 ) return -1 ; float a = 4 * ( pow ( r , 2 ) / 5 ) ; return a ; } int main ( ) { float r = 5 ; cout << squarearea ( r ) << endl ; return 0 ; }
Area of Largest rectangle that can be inscribed in an Ellipse | C ++ Program to find the biggest rectangle which can be inscribed within the ellipse ; Function to find the area of the rectangle ; a and b cannot be negative ; area of the rectangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float rectanglearea ( float a , float b ) { if ( a < 0 b < 0 ) return -1 ; return 2 * a * b ; } int main ( ) { float a = 10 , b = 8 ; cout << rectanglearea ( a , b ) << endl ; return 0 ; }
Area of a largest square fit in a right angle triangle | C ++ Program to find the area of the biggest square which can fit inside the right angled triangle ; Function to find the area of the biggest square ; the height or base or hypotenuse cannot be negative ; side of the square ; squaring to get the area ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float squareArea ( float l , float b , float h ) { if ( l < 0 b < 0 h < 0 ) return -1 ; float a = ( l * b ) / ( l + b ) ; return a * a ; } int main ( ) { float l = 5 , b = 12 , h = 13 ; cout << squareArea ( l , b , h ) << endl ; return 0 ; }
Queries to check if it is possible to join boxes in a circle | C ++ implementation of above approach ; Print the answer to each query ; setting the flag for exception ; replacing the greater element in i and j ; checking if that box is not used in previous query . ; checking if connecting to the same box ; case 1 : x < i and y lies between i and j ; case 2 : x lies between i and j and y > j ; if flag is not reset inbetween . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define MAX  50 NEW_LINE void solveQuery ( int n , int q , int qi [ ] , int qj [ ] ) { int arr [ MAX ] ; for ( int i = 0 ; i <= n ; i ++ ) arr [ i ] = 0 ; for ( int k = 0 ; k < q ; k ++ ) { int flag = 0 ; if ( qj [ k ] < qi [ k ] ) { int temp = qi [ k ] ; qi [ k ] = qj [ k ] ; qj [ k ] = temp ; } if ( arr [ qi [ k ] ] != 0 arr [ qj [ k ] ] != 0 ) flag = 1 ; else if ( qi [ k ] == qj [ k ] ) flag = 1 ; else { for ( int i = 1 ; i < qi [ k ] ; i ++ ) { if ( arr [ i ] != 0 && arr [ i ] < qj [ k ] && qi [ k ] < arr [ i ] ) { flag = 1 ; break ; } } if ( flag == 0 ) { for ( int i = qi [ k ] + 1 ; i < qj [ k ] ; i ++ ) { if ( arr [ i ] != 0 && arr [ i ] > qj [ k ] ) { flag = 1 ; break ; } } } } if ( flag == 0 ) { cout << " YES STRNEWLINE " ; arr [ qi [ k ] ] = qj [ k ] ; arr [ qj [ k ] ] = qi [ k ] ; } else cout << " NO STRNEWLINE " ; } } int main ( ) { int n = 10 ; int q = 7 ; int qi [ ] = { 1 , 2 , 2 , 2 , 9 , 10 , 8 } ; int qj [ ] = { 5 , 7 , 3 , 4 , 9 , 9 , 6 } ; solveQuery ( n , q , qi , qj ) ; return 0 ; }
Minimum squares to cover a rectangle | C ++ program to find the minimum number of squares to cover the surface of the rectangle with given dimensions ; function to count the number of squares that can cover the surface of the rectangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int squares ( int l , int b , int a ) { return ceil ( l / ( double ) a ) * ceil ( b / ( double ) a ) ; } int main ( ) { int l = 11 , b = 23 , a = 14 ; cout << squares ( l , b , a ) << endl ; return 0 ; }
Smallest square formed with given rectangles | C ++ Program to find the area of the smallest square which can be formed with rectangles of given dimensions ; Recursive function to return gcd of a and b ; Everything divides 0 ; Base case ; a is greater ; Function to find the area of the smallest square ; the length or breadth or side cannot be negative ; LCM of length and breadth ; squaring to get the area ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int gcd ( int a , int b ) { if ( a == 0 b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } int squarearea ( int l , int b ) { if ( l < 0 b < 0 ) return -1 ; int n = ( l * b ) / gcd ( l , b ) ; return n * n ; } int main ( ) { int l = 6 , b = 4 ; cout << squarearea ( l , b ) << endl ; return 0 ; }
Find all angles of a triangle in 3D | CPP program for finding all angles of a triangle ; function for finding the angle ; Driver code
#include <bits/stdc++.h> NEW_LINE #include <cmath> NEW_LINE using namespace std ; float angle_triangle ( int x1 , int x2 , int x3 , int y1 , int y2 , int y3 , int z1 , int z2 , int z3 ) { int num = ( x2 - x1 ) * ( x3 - x1 ) + ( y2 - y1 ) * ( y3 - y1 ) + ( z2 - z1 ) * ( z3 - z1 ) ; float den = sqrt ( pow ( ( x2 - x1 ) , 2 ) + pow ( ( y2 - y1 ) , 2 ) + pow ( ( z2 - z1 ) , 2 ) ) * sqrt ( pow ( ( x3 - x1 ) , 2 ) + pow ( ( y3 - y1 ) , 2 ) + pow ( ( z3 - z1 ) , 2 ) ) ; float angle = acos ( num / den ) * ( 180.0 / 3.141592653589793238463 ) ; return angle ; } int main ( ) { int x1 = -1 ; int y1 = 3 ; int z1 = 2 ; int x2 = 2 ; int y2 = 3 ; int z2 = 5 ; int x3 = 3 ; int y3 = 5 ; int z3 = -2 ; float angle_A = angle_triangle ( x1 , x2 , x3 , y1 , y2 , y3 , z1 , z2 , z3 ) ; float angle_B = angle_triangle ( x2 , x3 , x1 , y2 , y3 , y1 , z2 , z3 , z1 ) ; float angle_C = angle_triangle ( x3 , x2 , x1 , y3 , y2 , y1 , z3 , z2 , z1 ) ; cout << " Angles ▁ are ▁ : " << endl ; cout << setprecision ( 3 ) ; cout << " angle ▁ A ▁ = ▁ " << angle_A << " ▁ degree " << endl ; cout << " angle ▁ B ▁ = ▁ " << angle_B << " ▁ degree " << endl ; cout << " angle ▁ C ▁ = ▁ " << angle_C << " ▁ degree " << endl ; }
Minimum number of square tiles required to fill the rectangular floor | C ++ implementation of above approach ; Function to find the number of tiles ; if breadth is divisible by side of square ; tiles required is N / s ; one more tile required ; if length is divisible by side of square ; tiles required is M / s ; one more tile required ; Driver Code ; input length and breadth of rectangle and side of square
#include <bits/stdc++.h> NEW_LINE using namespace std ; int solve ( int M , int N , int s ) { if ( N % s == 0 ) { N = N / s ; } else { N = ( N / s ) + 1 ; } if ( M % s == 0 ) { M = M / s ; } else { M = ( M / s ) + 1 ; } return M * N ; } int main ( ) { int N = 12 , M = 13 , s = 4 ; cout << solve ( M , N , s ) ; return 0 ; }
Minimum number of square tiles required to fill the rectangular floor | C ++ implementation of above approach ; Function to find the number of tiles ; no of tiles ; Driver Code ; input length and breadth of rectangle and side of square
#include <bits/stdc++.h> NEW_LINE using namespace std ; int solve ( double M , double N , double s ) { int ans = ( ( int ) ( ceil ( M / s ) ) * ( int ) ( ceil ( N / s ) ) ) ; return ans ; } int main ( ) { double N = 12 , M = 13 , s = 4 ; cout << solve ( M , N , s ) ; return 0 ; }
Program to find equation of a plane passing through 3 points | C ++ program to find equation of a plane passing through given 3 points . ; Function to find equation of plane . ; Driver Code
#include <bits/stdc++.h> NEW_LINE #include <math.h> NEW_LINE #include <iostream> NEW_LINE #include <iomanip> NEW_LINE using namespace std ; void equation_plane ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 , float x3 , float y3 , float z3 ) { float a1 = x2 - x1 ; float b1 = y2 - y1 ; float c1 = z2 - z1 ; float a2 = x3 - x1 ; float b2 = y3 - y1 ; float c2 = z3 - z1 ; float a = b1 * c2 - b2 * c1 ; float b = a2 * c1 - a1 * c2 ; float c = a1 * b2 - b1 * a2 ; float d = ( - a * x1 - b * y1 - c * z1 ) ; std :: cout << std :: fixed ; std :: cout << std :: setprecision ( 2 ) ; cout << " equation ▁ of ▁ plane ▁ is ▁ " << a << " ▁ x ▁ + ▁ " << b << " ▁ y ▁ + ▁ " << c << " ▁ z ▁ + ▁ " << d << " ▁ = ▁ 0 . " ; } int main ( ) { float x1 = -1 ; float y1 = 2 ; float z1 = 1 ; float x2 = 0 ; float y2 = -3 ; float z2 = 2 ; float x3 = 1 ; float y3 = 1 ; float z3 = -4 ; equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) ; return 0 ; }
Program to determine the octant of the axial plane | C ++ program to print octant of a given point . ; Function to print octant ; Driver Code
#include <bits/stdc++.h> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void octant ( float x , float y , float z ) { if ( x >= 0 && y >= 0 && z >= 0 ) cout << " Point ▁ lies ▁ in ▁ 1st ▁ octant STRNEWLINE " ; else if ( x < 0 && y >= 0 && z >= 0 ) cout << " Point ▁ lies ▁ in ▁ 2nd ▁ octant STRNEWLINE " ; else if ( x < 0 && y < 0 && z >= 0 ) cout << " Point ▁ lies ▁ in ▁ 3rd ▁ octant STRNEWLINE " ; else if ( x >= 0 && y < 0 && z >= 0 ) cout << " Point ▁ lies ▁ in ▁ 4th ▁ octant STRNEWLINE " ; else if ( x >= 0 && y >= 0 && z < 0 ) cout << " Point ▁ lies ▁ in ▁ 5th ▁ octant STRNEWLINE " ; else if ( x < 0 && y >= 0 && z < 0 ) cout << " Point ▁ lies ▁ in ▁ 6th ▁ octant STRNEWLINE " ; else if ( x < 0 && y < 0 && z < 0 ) cout << " Point ▁ lies ▁ in ▁ 7th ▁ octant STRNEWLINE " ; else if ( x >= 0 && y < 0 && z < 0 ) cout << " Point ▁ lies ▁ in ▁ 8th ▁ octant STRNEWLINE " ; } int main ( ) { float x = 2 , y = 3 , z = 4 ; octant ( x , y , z ) ; x = -4 , y = 2 , z = -8 ; octant ( x , y , z ) ; x = -6 , y = -2 , z = 8 ; octant ( x , y , z ) ; return 0 ; }
Number of triangles in a plane if no more than two points are collinear | C ++ program to find the number of triangles in a plane if no more then two points are collinear . ; Function to find number of triangles in a plane . ; Formula to find number of triangles nC3 = n * ( n - 1 ) * ( n - 2 ) / 6 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countNumberOfTriangles ( int n ) { return n * ( n - 1 ) * ( n - 2 ) / 6 ; } int main ( ) { int n = 4 ; cout << countNumberOfTriangles ( n ) ; return 0 ; }
Centered Dodecagonal Number | C ++ Program to find nth centered Dodecagonal number ; Function to calculate Centered Dodecagonal number ; Formula to calculate nth centered Dodecagonal number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int centeredDodecagonal ( long int n ) { return 6 * n * ( n - 1 ) + 1 ; } int main ( ) { long int n = 2 ; cout << centeredDodecagonal ( n ) ; cout << endl ; n = 9 ; cout << centeredDodecagonal ( n ) ; return 0 ; }
Centered tridecagonal number | C ++ Program to find nth centered tridecagonal number ; Function to find nth centered tridecagonal number ; Formula to calculate nth centered tridecagonal number ; Drivers code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int centeredTridecagonalNum ( long int n ) { return ( 13 * n * ( n - 1 ) + 2 ) / 2 ; } int main ( ) { long int n = 3 ; cout << centeredTridecagonalNum ( n ) ; cout << endl ; n = 10 ; cout << centeredTridecagonalNum ( n ) ; return 0 ; }
Pentagonal Pyramidal Number | CPP Program to get nth Pentagonal pyramidal number . ; function to get nth Pentagonal pyramidal number . ; Running loop from 1 to n ; get nth pentagonal number ; add to sum ; Driver Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int pentagon_pyramidal ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int p = ( 3 * i * i - i ) / 2 ; sum = sum + p ; } return sum ; } int main ( ) { int n = 4 ; cout << pentagon_pyramidal ( n ) << endl ; return 0 ; }
Pentagonal Pyramidal Number | CPP Program to get nth Pentagonal pyramidal number . ; function to get nth Pentagonal pyramidal number . ; Driver Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int pentagon_pyramidal ( int n ) { return n * n * ( n + 1 ) / 2 ; } int main ( ) { int n = 4 ; cout << pentagon_pyramidal ( n ) << endl ; return 0 ; }
Check if three straight lines are concurrent or not | CPP Program to check if three straight line are concurrent or not ; Return true if three line are concurrent , else false . ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkConcurrent ( int a1 , int b1 , int c1 , int a2 , int b2 , int c2 , int a3 , int b3 , int c3 ) { return ( a3 * ( b1 * c2 - b2 * c1 ) + b3 * ( c1 * a2 - c2 * a1 ) + c3 * ( a1 * b2 - a2 * b1 ) == 0 ) ; } int main ( ) { int a1 = 2 , b1 = -3 , c1 = 5 ; int a2 = 3 , b2 = 4 , c2 = -7 ; int a3 = 9 , b3 = -5 , c3 = 8 ; ( checkConcurrent ( a1 , b1 , c1 , a2 , b2 , c2 , a3 , b3 , c3 ) ? ( cout << " Yes " ) : ( cout << " No " ) ) ; return 0 ; }
Centered Octadecagonal Number | C ++ Program to find the nth centered octadecagonal number ; centered octadecagon function ; Formula to calculate nth centered octadecagonal number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int center_octadecagon_num ( long int n ) { return 9 * n * n - 9 * n + 1 ; } int main ( ) { long int n = 3 ; cout << n << " th ▁ centered ▁ octadecagonal ▁ number ▁ : ▁ " << center_octadecagon_num ( n ) ; cout << endl ; n = 13 ; cout << n << " th ▁ centered ▁ octadecagonal ▁ number ▁ : ▁ " << center_octadecagon_num ( n ) ; return 0 ; }
Centered decagonal number | Program to find nth centered decagonal number ; Centered decagonal number function ; Formula to calculate nth centered decagonal number & return it into main function . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int centereddecagonalnum ( int n ) { return ( 5 * n * n + 5 * n + 1 ) ; } int main ( ) { int n = 5 ; cout << n << " th ▁ centered ▁ decagonal " << " number : ▁ " ; cout << centereddecagonalnum ( n ) ; cout << endl ; n = 9 ; cout << n << " th ▁ centered ▁ decagonal " << " number : ▁ " ; cout << centereddecagonalnum ( n ) ; return 0 ; }
Lexicographically Kth smallest way to reach given coordinate from origin | CPP Program to find Lexicographically Kth smallest way to reach given coordinate from origin ; Return ( a + b ) ! / a ! b ! ; finding ( a + b ) ! ; finding ( a + b ) ! / a ! ; finding ( a + b ) ! / b ! ; Return the Kth smallest way to reach given coordinate from origin ; if at origin ; if on y - axis ; decrement y . ; Move vertical ; recursive call to take next step . ; If on x - axis ; decrement x . ; Move horizontal . ; recursive call to take next step . ; If x + y C x is greater than K ; Move Horizontal ; recursive call to take next step . ; Move vertical ; recursive call to take next step . ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int factorial ( int a , int b ) { int res = 1 ; for ( int i = 1 ; i <= ( a + b ) ; i ++ ) res = res * i ; for ( int i = 1 ; i <= a ; i ++ ) res = res / i ; for ( int i = 1 ; i <= b ; i ++ ) res = res / i ; return res ; } void Ksmallest ( int x , int y , int k ) { if ( x == 0 && y == 0 ) return ; else if ( x == 0 ) { y -- ; cout << " V " ; Ksmallest ( x , y , k ) ; } else if ( y == 0 ) { x -- ; cout << " H " ; Ksmallest ( x , y , k ) ; } else { if ( factorial ( x - 1 , y ) > k ) { cout << " H " ; Ksmallest ( x - 1 , y , k ) ; } else { cout << " V " ; Ksmallest ( x , y - 1 , k - factorial ( x - 1 , y ) ) ; } } } int main ( ) { int x = 2 , y = 2 , k = 2 ; Ksmallest ( x , y , k ) ; return 0 ; }
Centered pentagonal number | Program to find nth Centered pentagonal number . ; centered pentagonal number function ; Formula to calculate nth Centered pentagonal number and return it into main function . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int centered_pentagonal_Num ( int n ) { return ( 5 * n * n - 5 * n + 2 ) / 2 ; } int main ( ) { int n = 7 ; cout << n << " th ▁ Centered ▁ pentagonal ▁ number : ▁ " ; cout << centered_pentagonal_Num ( n ) ; return 0 ; }
Find maximum and minimum distance between magnets | C ++ program for max and min distance ; Function for finding distance between pivots ; Function for minimum distance ; Function for maximum distance ; Drivers code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int pivotDis ( int x0 , int y0 , int x1 , int y1 ) { return sqrt ( ( x1 - x0 ) * ( x1 - x0 ) + ( y1 - y0 ) * ( y1 - y0 ) ) ; } int minDis ( int D , int r1 , int r2 ) { return max ( ( D - r1 - r2 ) , 0 ) ; } int maxDis ( int D , int r1 , int r2 ) { return D + r1 + r2 ; } int main ( ) { int x0 = 0 , y0 = 0 , x1 = 8 , y1 = 0 , r1 = 4 , r2 = 5 ; int D = pivotDis ( x0 , y0 , x1 , y1 ) ; cout << " Distance ▁ while ▁ repulsion ▁ = ▁ " << maxDis ( D , r1 , r2 ) ; cout << " Distance while attraction = " return 0 ; }
Maximize a value for a semicircle of given radius | C ++ program to find the maximum value of F ; Function to find the maximum value of F ; using the formula derived for getting the maximum value of F ; Drivers code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double maximumValueOfF ( int R ) { return 4 * R * R + 0.25 ; } int main ( ) { int R = 3 ; printf ( " % .2f " , maximumValueOfF ( R ) ) ; return 0 ; }