codeparrot/xlcost-text-to-code huggingface dataset:
Check whether two points ( x1 , y1 ) and ( x2 , y2 ) lie on same side of a given line or not | C ++ program to check if two points lie on the same side or not ; Function to check if two points lie on the same side or not ; int fx1 ; Variable to store a * x1 + b * y1 - c int fx2 ; Variable to store a * x2 + b * y2 - c ; If fx1 and fx2 have same sign ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool pointsAreOnSameSideOfLine ( int a , int b , int c , int x1 , int y1 , int x2 , int y2 ) { fx1 = a * x1 + b * y1 - c ; fx2 = a * x2 + b * y2 - c ; if ( ( fx1 * fx2 ) > 0 ) return true ; return false ; } int main ( ) { int a = 1 , b = 1 , c = 1 ; int x1 = 1 , y1 = 1 ; int x2 = 2 , y2 = 1 ; if ( pointsAreOnSameSideOfLine ( a , b , c , x1 , y1 , x2 , y2 ) ) cout << " Yes " ; else cout << " No " ; }
Percentage increase in volume of the cube if a side of cube is increased by a given percentage | C ++ program to find percentage increase in the volume of the cube if a side of cube is increased by a given percentage ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void newvol ( double x ) { cout << " percentage ▁ increase ▁ " << " in ▁ the ▁ volume ▁ of ▁ the ▁ cube ▁ is ▁ " << pow ( x , 3 ) / 10000 + 3 * x + ( 3 * pow ( x , 2 ) ) / 100 << " % " << endl ; } int main ( ) { double x = 10 ; newvol ( x ) ; return 0 ; }
Number of triangles formed by joining vertices of n | C ++ program to implement the above problem ; Function to find the number of triangles ; print the number of triangles having two side common ; print the number of triangles having no side common ; Driver code ; initialize the number of sides of a polygon
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findTriangles ( int n ) { int num = n ; cout << num << " ▁ " ; cout << num * ( num - 4 ) * ( num - 5 ) / 6 ; } int main ( ) { int n ; n = 6 ; findTriangles ( n ) ; return 0 ; }
Find the radii of the circles which are lined in a row , and distance between the centers of first and last circle is given | C ++ program to find radii of the circles which are lined in a row and distance between the centers of first and last circle is given ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void radius ( int n , int d ) { cout << " The ▁ radius ▁ of ▁ each ▁ circle ▁ is ▁ " << d / ( 2 * n - 2 ) << endl ; } int main ( ) { int d = 42 , n = 4 ; radius ( n , d ) ; return 0 ; }
Find the side of the squares which are lined in a row , and distance between the centers of first and last square is given | C ++ program to find side of the squares which are lined in a row and distance between the centers of first and last squares is given ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void radius ( int n , int d ) { cout << " The ▁ side ▁ of ▁ each ▁ square ▁ is ▁ " << d / ( n - 1 ) << endl ; } int main ( ) { int d = 42 , n = 4 ; radius ( n , d ) ; return 0 ; }
Number of triangles formed by joining vertices of n | C ++ program to implement the above problem ; Function to find the number of triangles ; print the number of triangles ; Driver code ; initialize the number of sides of a polygon
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findTriangles ( int n ) { int num ; num = n * ( n - 4 ) ; cout << num ; } int main ( ) { int n ; n = 6 ; findTriangles ( n ) ; return 0 ; }
Find the Diameter or Longest chord of a Circle | C ++ program to find the longest chord or diameter of the circle whose radius is given ; Function to find the longest chord ; Driver code ; Get the radius ; Find the diameter
#include <bits/stdc++.h> NEW_LINE using namespace std ; void diameter ( double r ) { cout << " The ▁ length ▁ of ▁ the ▁ longest ▁ chord " << " ▁ or ▁ diameter ▁ of ▁ the ▁ circle ▁ is ▁ " << 2 * r << endl ; } int main ( ) { double r = 4 ; diameter ( r ) ; return 0 ; }
Slope of the line parallel to the line with the given slope | C ++ implementation of the approach ; Function to return the slope of the line which is parallel to the line with the given slope ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double getSlope ( double m ) { return m ; } int main ( ) { double m = 2 ; cout << getSlope ( m ) ; return 0 ; }
Total number of triangles formed when there are H horizontal and V vertical lines | C ++ implementation of the approach ; Function to return total triangles ; Only possible triangle is the given triangle ; If only vertical lines are present ; If only horizontal lines are present ; Return total triangles ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define LLI  long long int NEW_LINE LLI totalTriangles ( LLI h , LLI v ) { if ( h == 0 && v == 0 ) return 1 ; if ( h == 0 ) return ( ( v + 1 ) * ( v + 2 ) / 2 ) ; if ( v == 0 ) return ( h + 1 ) ; LLI Total = ( h + 1 ) * ( ( v + 1 ) * ( v + 2 ) / 2 ) ; return Total ; } int main ( ) { int h = 2 , v = 2 ; cout << totalTriangles ( h , v ) ; return 0 ; }
Largest sphere that can be inscribed in a right circular cylinder inscribed in a frustum | C ++ Program to find the biggest sphere that can be inscribed within a right circular cylinder which in turn is inscribed within a frustum ; Function to find the biggest sphere ; the radii and height cannot be negative ; radius of the sphere ; volume of the sphere ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float sph ( float r , float R , float h ) { if ( r < 0 && R < 0 && h < 0 ) return -1 ; float x = r ; float V = ( 4 * 3.14 * pow ( r , 3 ) ) / 3 ; return V ; } int main ( ) { float r = 5 , R = 8 , h = 11 ; cout << sph ( r , R , h ) << endl ; return 0 ; }
Check whether two straight lines are orthogonal or not | C ++ implementation of above approach ; Function to check if two straight lines are orthogonal or not ; Both lines have infinite slope ; Only line 1 has infinite slope ; Only line 2 has infinite slope ; Find slopes of the lines ; Check if their product is - 1 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkOrtho ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x4 , int y4 ) { int m1 , m2 ; if ( x2 - x1 == 0 && x4 - x3 == 0 ) return false ; else if ( x2 - x1 == 0 ) { m2 = ( y4 - y3 ) / ( x4 - x3 ) ; if ( m2 == 0 ) return true ; else return false ; } else if ( x4 - x3 == 0 ) { m1 = ( y2 - y1 ) / ( x2 - x1 ) ; if ( m1 == 0 ) return true ; else return false ; } else { m1 = ( y2 - y1 ) / ( x2 - x1 ) ; m2 = ( y4 - y3 ) / ( x4 - x3 ) ; if ( m1 * m2 == -1 ) return true ; else return false ; } } int main ( ) { int x1 = 0 , y1 = 4 , x2 = 0 , y2 = -9 ; int x3 = 2 , y3 = 0 , x4 = -1 , y4 = 0 ; checkOrtho ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) ? cout << " Yes " : cout << " No " ; return 0 ; }
Diagonal of a Regular Pentagon | C ++ Program to find the diagonal of a regular pentagon ; Function to find the diagonal of a regular pentagon ; Side cannot be negative ; Length of the diagonal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float pentdiagonal ( float a ) { if ( a < 0 ) return -1 ; float d = 1.22 * a ; return d ; } int main ( ) { float a = 6 ; cout << pentdiagonal ( a ) << endl ; return 0 ; }
Area of hexagon with given diagonal length | C ++ program to find the area of Hexagon with given diagonal ; Function to calculate area ; Formula to find area ; Main
#include <bits/stdc++.h> NEW_LINE using namespace std ; float hexagonArea ( float d ) { return ( 3 * sqrt ( 3 ) * pow ( d , 2 ) ) / 8 ; } int main ( ) { float d = 10 ; cout << " Area ▁ of ▁ hexagon : ▁ " << hexagonArea ( d ) ; return 0 ; }
Number of squares of side length required to cover an N * M rectangle | CPP program to find number of squares of a * a required to cover n * m rectangle ; function to find number of squares of a * a required to cover n * m rectangle ; Driver code ; function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Squares ( int n , int m , int a ) { return ( ( m + a - 1 ) / a ) * ( ( n + a - 1 ) / a ) ; } int main ( ) { int n = 6 , m = 6 , a = 4 ; cout << Squares ( n , m , a ) ; return 0 ; }
Length of the Diagonal of the Octagon | C ++ Program to find the diagonal of the octagon ; Function to find the diagonal of the octagon ; side cannot be negative ; diagonal of the octagon ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float octadiagonal ( float a ) { if ( a < 0 ) return -1 ; return a * sqrt ( 4 + ( 2 * sqrt ( 2 ) ) ) ; } int main ( ) { float a = 4 ; cout << octadiagonal ( a ) << endl ; return 0 ; }
Program to Calculate the Perimeter of a Decagon | C ++ program to Calculate the Perimeter of a Decagon ; Function for finding the perimeter ; Driver code
#include <iostream> NEW_LINE using namespace std ; void CalPeri ( ) { int s = 5 , Perimeter ; Perimeter = 10 * s ; cout << " The ▁ Perimeter ▁ of ▁ Decagon ▁ is ▁ : ▁ " << Perimeter ; } int main ( ) { CalPeri ( ) ; return 0 ; }
Sum of lengths of all 12 edges of any rectangular parallelepiped | C ++ program to illustrate the above problem ; function to find the sum of all the edges of parallelepiped ; to calculate the length of one edge ; sum of all the edges of one side ; net sum will be equal to the summation of edges of all the sides ; Driver code ; initialize the area of three faces which has a common vertex
#include <bits/stdc++.h> NEW_LINE using namespace std ; double findEdges ( double s1 , double s2 , double s3 ) { double a = sqrt ( s1 * s2 / s3 ) ; double b = sqrt ( s3 * s1 / s2 ) ; double c = sqrt ( s3 * s2 / s1 ) ; double sum = a + b + c ; return 4 * sum ; } int main ( ) { double s1 , s2 , s3 ; s1 = 65 , s2 = 156 , s3 = 60 ; cout << findEdges ( s1 , s2 , s3 ) ; return 0 ; }
Maximum number of pieces in N cuts | C ++ program to find maximum no of pieces by given number of cuts ; Function for finding maximum pieces with n cuts . ; to maximize number of pieces x is the horizontal cuts ; Now ( x ) is the horizontal cuts and ( n - x ) is vertical cuts , then maximum number of pieces = ( x + 1 ) * ( n - x + 1 ) ; Driver code ; Taking the maximum number of cuts allowed as 3 ; Finding and printing the max number of pieces
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMaximumPieces ( int n ) { int x = n / 2 ; return ( ( x + 1 ) * ( n - x + 1 ) ) ; } int main ( ) { int n = 3 ; cout << " Max ▁ number ▁ of ▁ pieces ▁ for ▁ n ▁ = ▁ " << n << " ▁ is ▁ " << findMaximumPieces ( 3 ) ; return 0 ; }
Program to check whether 4 points in a 3 | C ++ program to check if 4 points in a 3 - D plane are Coplanar ; Function to find equation of plane . ; checking if the 4 th point satisfies the above equation ; Driver Code ; function calling
#include <bits/stdc++.h> NEW_LINE using namespace std ; void equation_plane ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 , int x3 , int y3 , int z3 , int x , int y , int z ) { int a1 = x2 - x1 ; int b1 = y2 - y1 ; int c1 = z2 - z1 ; int a2 = x3 - x1 ; int b2 = y3 - y1 ; int c2 = z3 - z1 ; int a = b1 * c2 - b2 * c1 ; int b = a2 * c1 - a1 * c2 ; int c = a1 * b2 - b1 * a2 ; int d = ( - a * x1 - b * y1 - c * z1 ) ; if ( a * x + b * y + c * z + d == 0 ) cout << " Coplanar " << endl ; else cout << " Not ▁ Coplanar " << endl ; } int main ( ) { int x1 = 3 ; int y1 = 2 ; int z1 = -5 ; int x2 = -1 ; int y2 = 4 ; int z2 = -3 ; int x3 = -3 ; int y3 = 8 ; int z3 = -5 ; int x4 = -3 ; int y4 = 2 ; int z4 = 1 ; equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 , x4 , y4 , z4 ) ; return 0 ; }
Angle between two Planes in 3D | C ++ program to find the Angle between two Planes in 3 D . ; Function to find Angle ; Driver Code
#include <bits/stdc++.h> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void distance ( float a1 , float b1 , float c1 , float a2 , float b2 , float c2 ) { float d = ( a1 * a2 + b1 * b2 + c1 * c2 ) ; float e1 = sqrt ( a1 * a1 + b1 * b1 + c1 * c1 ) ; float e2 = sqrt ( a2 * a2 + b2 * b2 + c2 * c2 ) ; d = d / ( e1 * e2 ) ; float pi = 3.14159 ; float A = ( 180 / pi ) * ( acos ( d ) ) ; cout << " Angle ▁ is ▁ " << A << " ▁ degree " ; } int main ( ) { float a1 = 1 ; float b1 = 1 ; float c1 = 2 ; float d1 = 1 ; float a2 = 2 ; float b2 = -1 ; float c2 = 1 ; float d2 = -4 ; distance ( a1 , b1 , c1 , a2 , b2 , c2 ) ; return 0 ; }
Mirror of a point through a 3 D plane | C ++ program to find Mirror of a point through a 3 D plane ; Function to mirror image ; Driver Code ; function call
#include <bits/stdc++.h> NEW_LINE #include <math.h> NEW_LINE #include <iostream> NEW_LINE #include <iomanip> NEW_LINE using namespace std ; void mirror_point ( float a , float b , float c , float d , float x1 , float y1 , float z1 ) { float k = ( - a * x1 - b * y1 - c * z1 - d ) / ( float ) ( a * a + b * b + c * c ) ; float x2 = a * k + x1 ; float y2 = b * k + y1 ; float z2 = c * k + z1 ; float x3 = 2 * x2 - x1 ; float y3 = 2 * y2 - y1 ; float z3 = 2 * z2 - z1 ; std :: cout << std :: fixed ; std :: cout << std :: setprecision ( 1 ) ; cout << " ▁ x3 ▁ = ▁ " << x3 ; cout << " ▁ y3 ▁ = ▁ " << y3 ; cout << " ▁ z3 ▁ = ▁ " << z3 ; } int main ( ) { float a = 1 ; float b = -2 ; float c = 0 ; float d = 0 ; float x1 = -1 ; float y1 = 3 ; float z1 = 4 ; mirror_point ( a , b , c , d , x1 , y1 , z1 ) ; return 0 ; }
Number of rectangles in a circle of radius R | C ++ program to find the number of rectangles that can be cut from a circle of Radius R ; Function to return the total possible rectangles that can be cut from the circle ; Diameter = 2 * Radius ; Square of diameter which is the square of the maximum length diagonal ; generate all combinations of a and b in the range ( 1 , ( 2 * Radius - 1 ) ) ( Both inclusive ) ; Calculate the Diagonal length of this rectangle ; If this rectangle 's Diagonal Length  is less than the Diameter, it is a  valid rectangle, thus increment counter ; Driver Code ; Radius of the circle
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countRectangles ( int radius ) { int rectangles = 0 ; int diameter = 2 * radius ; int diameterSquare = diameter * diameter ; for ( int a = 1 ; a < 2 * radius ; a ++ ) { for ( int b = 1 ; b < 2 * radius ; b ++ ) { int diagonalLengthSquare = ( a * a + b * b ) ; if ( diagonalLengthSquare <= diameterSquare ) { rectangles ++ ; } } } return rectangles ; } int main ( ) { int radius = 2 ; int totalRectangles ; totalRectangles = countRectangles ( radius ) ; cout << totalRectangles << " ▁ rectangles ▁ can ▁ be " << " cut ▁ from ▁ a ▁ circle ▁ of ▁ Radius ▁ " << radius ; return 0 ; }
Program to check similarity of given two triangles | C ++ program to check similarity between two triangles . ; Function for AAA similarity ; Check for AAA ; Function for SAS similarity ; angle b / w two smallest sides is largest . ; since we take angle b / w the sides . ; Function for SSS similarity ; Check for SSS ; Driver Code ; function call for AAA similarity ; function call for SSS similarity ; function call for SAS similarity ; Check if triangles are similar or not
#include <bits/stdc++.h> NEW_LINE using namespace std ; int simi_aaa ( int a1 [ ] , int a2 [ ] ) { sort ( a1 , a1 + 3 ) ; sort ( a2 , a2 + 3 ) ; if ( a1 [ 0 ] == a2 [ 0 ] && a1 [ 1 ] == a2 [ 1 ] && a1 [ 2 ] == a2 [ 2 ] ) return 1 ; else return 0 ; } int simi_sas ( int s1 [ ] , int s2 [ ] , int a1 [ ] , int a2 [ ] ) { sort ( a1 , a1 + 3 ) ; sort ( a2 , a2 + 3 ) ; sort ( s1 , s1 + 3 ) ; sort ( s2 , s2 + 3 ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] ) { if ( a1 [ 2 ] == a2 [ 2 ] ) return 1 ; } if ( s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] ) { if ( a1 [ 0 ] == a2 [ 0 ] ) return 1 ; } if ( s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) { if ( a1 [ 1 ] == a2 [ 1 ] ) return 1 ; } return 0 ; } int simi_sss ( int s1 [ ] , int s2 [ ] ) { sort ( s1 , s1 + 3 ) ; sort ( s2 , s2 + 3 ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] && s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] && s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) return 1 ; return 0 ; } int main ( ) { int s1 [ ] = { 2 , 3 , 3 } ; int s2 [ ] = { 4 , 6 , 6 } ; int a1 [ ] = { 80 , 60 , 40 } ; int a2 [ ] = { 40 , 60 , 80 } ; int aaa = simi_aaa ( a1 , a2 ) ; int sss = simi_sss ( s1 , s2 ) ; int sas = simi_sas ( s1 , s2 , a1 , a2 ) ; if ( aaa == 1 sss == 1 sas == 1 ) { cout << " Triangles ▁ are ▁ " << " similar ▁ by ▁ " ; if ( aaa == 1 ) cout << " AAA ▁ " ; if ( sss == 1 ) cout << " SSS ▁ " ; if ( sas == 1 ) cout << " SAS . " ; } else cout << " Triangles ▁ are ▁ " << " not ▁ similar " ; return 0 ; }
Centered Pentadecagonal Number | C ++ Program to find nth centered pentadecagonal number ; centered pentadecagonal function ; Formula to calculate nth centered pentadecagonal number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int center_pentadecagonal_num ( long int n ) { return ( 15 * n * n - 15 * n + 2 ) / 2 ; } int main ( ) { long int n = 3 ; cout << n << " th ▁ number ▁ : ▁ " << center_pentadecagonal_num ( n ) ; cout << endl ; n = 10 ; cout << n << " th ▁ number ▁ : ▁ " << center_pentadecagonal_num ( n ) ; return 0 ; }
Centered nonadecagonal number | C ++ Program to find nth centered nonadecagonal number ; centered nonadecagonal function ; Formula to calculate nth centered nonadecagonal number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int center_nonadecagon_num ( long int n ) { return ( 19 * n * n - 19 * n + 2 ) / 2 ; } int main ( ) { long int n = 2 ; cout << n << " th ▁ centered ▁ nonadecagonal ▁ number ▁ : ▁ " << center_nonadecagon_num ( n ) ; cout << endl ; n = 7 ; cout << n << " th ▁ centered ▁ nonadecagonal ▁ number ▁ : ▁ " << center_nonadecagon_num ( n ) ; return 0 ; }
Hendecagonal number | C ++ program to find nth Hendecagonal number ; Function to find Hendecagonal number ; Formula to calculate nth Hendecagonal number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int hendecagonal_num ( int n ) { return ( 9 * n * n - 7 * n ) / 2 ; } int main ( ) { int n = 3 ; cout << n << " rd ▁ Hendecagonal ▁ number : ▁ " ; cout << hendecagonal_num ( n ) ; cout << endl ; n = 10 ; cout << n << " th ▁ Hendecagonal ▁ number : ▁ " ; cout << hendecagonal_num ( n ) ; return 0 ; }
Centered Octagonal Number | Program to find nth centered octagonal number ; Centered octagonal number function ; Formula to calculate nth centered octagonal number & return it into main function . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int cen_octagonalnum ( long int n ) { return ( 4 * n * n - 4 * n + 1 ) ; } int main ( ) { long int n = 6 ; cout << n << " th ▁ centered " << " ▁ octagonal ▁ number ▁ : ▁ " ; cout << cen_octagonalnum ( n ) ; cout << endl ; n = 11 ; cout << n << " th ▁ centered " << " ▁ octagonal ▁ number ▁ : ▁ " ; cout << cen_octagonalnum ( n ) ; return 0 ; }
Number of ordered points pair satisfying line equation | CPP code to count the number of ordered pairs satisfying Line Equation ; Checks if ( i , j ) is valid , a point ( i , j ) is valid if point ( arr [ i ] , arr [ j ] ) satisfies the equation y = mx + c And i is not equal to j ; check if i equals to j ; Equation LHS = y , and RHS = mx + c ; Returns the number of ordered pairs ( i , j ) for which point ( arr [ i ] , arr [ j ] ) satisfies the equation of the line y = mx + c ; for every possible ( i , j ) check if ( a [ i ] , a [ j ] ) satisfies the equation y = mx + c ; ( firstIndex , secondIndex ) is same as ( i , j ) ; check if ( firstIndex , secondIndex ) is a valid point ; Driver Code ; equation of line is y = mx + c
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isValid ( int arr [ ] , int i , int j , int m , int c ) { if ( i == j ) return false ; int lhs = arr [ j ] ; int rhs = m * arr [ i ] + c ; return ( lhs == rhs ) ; } int findOrderedPoints ( int arr [ ] , int n , int m , int c ) { int counter = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { int firstIndex = i , secondIndex = j ; if ( isValid ( arr , firstIndex , secondIndex , m , c ) ) counter ++ ; } } return counter ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int m = 1 , c = 1 ; cout << findOrderedPoints ( arr , n , m , c ) ; return 0 ; }
Check if a given circle lies completely inside the ring formed by two concentric circles | CPP code to check if a circle lies in the ring ; Function to check if circle lies in the ring ; distance between center of circle center of concentric circles ( origin ) using Pythagoras theorem ; Condition to check if circle is strictly inside the ring ; Driver Code ; Both circle with radius ' r ' and ' R ' have center ( 0 , 0 )
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) { int dis = sqrt ( x1 * x1 + y1 * y1 ) ; return ( dis - r1 >= R && dis + r1 <= r ) ; } int main ( ) { int r = 8 , R = 4 , r1 = 2 , x1 = 6 , y1 = 0 ; if ( checkcircle ( r , R , r1 , x1 , y1 ) ) cout << " yes " << endl ; else cout << " no " << endl ; return 0 ; }
Program for Surface Area of Octahedron | CPP Program to calculate surface area of Octahedron ; utility Function ; Driver Function
#include <bits/stdc++.h> NEW_LINE using namespace std ; double surface_area_octahedron ( double side ) { return ( 2 * ( sqrt ( 3 ) ) * ( side * side ) ) ; } int main ( ) { double side = 7 ; cout << " Surface ▁ area ▁ of ▁ octahedron ▁ = " << surface_area_octahedron ( side ) << endl ; }
Count of different straight lines with total n points with m collinear | CPP program to count number of straight lines with n total points , out of which m are collinear . ; Returns value of binomial coefficient Code taken from https : goo . gl / vhy4jp ; C [ 0 ] = 1 ; nC0 is 1 ; Compute next row of pascal triangle using the previous row ; function to calculate number of straight lines can be formed ; driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int nCk ( int n , int k ) { int C [ k + 1 ] ; memset ( C , 0 , sizeof ( C ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } int count_Straightlines ( int n , int m ) { return ( nCk ( n , 2 ) - nCk ( m , 2 ) + 1 ) ; } int main ( ) { int n = 4 , m = 3 ; cout << count_Straightlines ( n , m ) ; return 0 ; }
Calculate Volume of Dodecahedron | CPP program to calculate Volume of dodecahedron ; utility Function ; Driver Function
#include <bits/stdc++.h> NEW_LINE using namespace std ; double vol_of_dodecahedron ( int side ) { return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side , 3 ) ) ) ; } int main ( ) { int side = 4 ; cout << " Volume ▁ of ▁ dodecahedron ▁ = ▁ " << vol_of_dodecahedron ( side ) ; }
Program to check if water tank overflows when n solid balls are dipped in the water tank | C ++ Program to check if water tank overflows when n solid balls are dipped in the water tank ; function to find if tak will overflow or not ; cylinder capacity ; volume of water in tank ; volume of n balls ; total volume of water and n dipped balls ; condition to check if tank is in overflow state or not ; main function ; giving dimensions ; calling function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void overflow ( int H , int r , int h , int N , int R ) { float tank_cap = 3.14 * r * r * H ; float water_vol = 3.14 * r * r * h ; float balls_vol = N * ( 4 / 3 ) * 3.14 * R * R * R ; float vol = water_vol + balls_vol ; if ( vol > tank_cap ) { cout << " Overflow " << endl ; } else { cout << " Not ▁ in ▁ overflow ▁ state " << endl ; } } int main ( ) { int H = 10 , r = 5 , h = 5 , N = 2 , R = 2 ; overflow ( H , r , h , N , R ) ; return 0 ; }