text
stringlengths
17
4.49k
code
stringlengths
49
5.46k
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 ; }
Diagonal of a Regular Heptagon | C ++ Program to find the diagonal of a regular heptagon ; Function to return the diagonal of a regular heptagon ; Side cannot be negative ; Length of the diagonal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float heptdiagonal ( float a ) { if ( a < 0 ) return -1 ; float d = 1.802 * a ; return d ; } int main ( ) { float a = 6 ; cout << heptdiagonal ( a ) << endl ; return 0 ; }
Diagonal of a Regular Hexagon | C ++ Program to find the diagonal of a regular hexagon ; Function to find the diagonal of a regular hexagon ; Side cannot be negative ; Length of the diagonal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float hexDiagonal ( float a ) { if ( a < 0 ) return -1 ; float d = 1.73 * a ; return d ; } int main ( ) { float a = 9 ; cout << hexDiagonal ( a ) << endl ; return 0 ; }
Area of Reuleaux Triangle | C ++ Program to find the area of Reuleaux triangle ; Function to find the Area of the Reuleaux triangle ; Side cannot be negative ; Area of the Reuleaux triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float ReuleauxArea ( float a ) { if ( a < 0 ) return -1 ; float A = 0.70477 * pow ( a , 2 ) ; return A ; } int main ( ) { float a = 6 ; cout << ReuleauxArea ( a ) << endl ; return 0 ; }
Largest Square that can be inscribed within a hexagon | C ++ program to find the area of the largest square that can be inscribed within the hexagon ; Function to find the area of the square ; Side cannot be negative ; Area of the square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float squareArea ( float a ) { if ( a < 0 ) return -1 ; float area = pow ( 1.268 , 2 ) * pow ( a , 2 ) ; return area ; } int main ( ) { float a = 6 ; cout << squareArea ( a ) << endl ; return 0 ; }
Volume of cube using its space diagonal | C ++ program to find the volume occupied by Cube with given space diagonal ; Function to calculate Volume ; Formula to find Volume ; Drivers code ; space diagonal of Cube
#include <bits/stdc++.h> NEW_LINE using namespace std ; float CubeVolume ( float d ) { float Volume ; Volume = ( sqrt ( 3 ) * pow ( d , 3 ) ) / 9 ; return Volume ; } int main ( ) { float d = 5 ; cout << " Volume ▁ of ▁ Cube : ▁ " << CubeVolume ( d ) ; return 0 ; }
Length of rope tied around three equal circles touching each other | C ++ program to find the length of rope ; Function to find the length of rope ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define PI 3.14159265 NEW_LINE float length_rope ( float r ) { return ( ( 2 * PI * r ) + 6 * r ) ; } int main ( ) { float r = 7 ; cout << ceil ( length_rope ( r ) ) << endl ; return 0 ; }
Number of triangles that can be formed with given N points | C ++ implementation of the above approach ; This function returns the required number of triangles ; Hash Map to store the frequency of slope corresponding to a point ( X , Y ) ; Iterate over all possible points ; Calculate slope of all elements with current element ; find the slope with reduced fraction ; Total number of ways to form a triangle having one point as current element ; Subtracting the total number of ways to form a triangle having the same slope or are collinear ; Driver Code to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countTriangles ( pair < int , int > P [ ] , int N ) { map < pair < int , int > , int > mp ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { mp . clear ( ) ; for ( int j = i + 1 ; j < N ; j ++ ) { int X = P [ i ] . first - P [ j ] . first ; int Y = P [ i ] . second - P [ j ] . second ; int g = __gcd ( X , Y ) ; X /= g ; Y /= g ; mp [ { X , Y } ] ++ ; } int num = N - ( i + 1 ) ; ans += ( num * ( num - 1 ) ) / 2 ; for ( auto j : mp ) ans -= ( j . second * ( j . second - 1 ) ) / 2 ; } return ans ; } int main ( ) { pair < int , int > P [ ] = { { 0 , 0 } , { 2 , 0 } , { 1 , 1 } , { 2 , 2 } } ; int N = sizeof ( P ) / sizeof ( P [ 0 ] ) ; cout << countTriangles ( P , N ) << endl ; return 0 ; }
Area of Circumcircle of a Right Angled Triangle | C ++ program to find the area of Cicumscribed circle of right angled triangle ; Function to find area of circumscribed circle ; Driver code
#include <bits/stdc++.h> NEW_LINE #define PI 3.14159265 NEW_LINE using namespace std ; float area_circumscribed ( float c ) { return ( c * c * ( PI / 4 ) ) ; } int main ( ) { float c = 8 ; cout << area_circumscribed ( c ) ; return 0 ; }
Largest right circular cylinder that can be inscribed within a cone | C ++ Program to find the biggest right circular cylinder that can be fit within a right circular cone ; Function to find the biggest right circular cylinder ; radius and height 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 r , float h ) { if ( r < 0 && h < 0 ) return -1 ; float R = ( 2 * r ) / 3 ; float H = ( 2 * h ) / 3 ; float V = 3.14 * pow ( R , 2 ) * H ; return V ; } int main ( ) { float r = 4 , h = 8 ; cout << cyl ( r , h ) << endl ; return 0 ; }
Largest cube that can be inscribed within a right circular cylinder | C ++ Program to find the biggest cube inscribed within a right circular cylinder ; Function to find the volume of the cube ; height and radius cannot be negative ; volume of the cube ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float cube ( float h , float r ) { if ( h < 0 && r < 0 ) return -1 ; float a = pow ( h , 3 ) ; return a ; } int main ( ) { float h = 5 , r = 4 ; cout << cube ( h , r ) << endl ; return 0 ; }
Volume of biggest sphere within a right circular cylinder | C ++ Program to find the biggest sphere that can be fit within a right circular cylinder ; Function to find the biggest sphere ; radius and height cannot be negative ; radius of sphere ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float sph ( float r , float h ) { if ( r < 0 && h < 0 ) return -1 ; float R = r ; return R ; } int main ( ) { float r = 4 , h = 8 ; cout << sph ( r , h ) << endl ; return 0 ; }
Volume of largest right circular cylinder within a Sphere | C ++ Program to find the biggest right circular cylinder that can be fit within a sphere ; Function to find the biggest right circular cylinder ; radius cannot be negative ; volume of cylinder ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float cyl ( float R ) { if ( R < 0 ) return -1 ; float V = ( 2 * 3.14 * pow ( R , 3 ) ) / ( 3 * sqrt ( 3 ) ) ; return V ; } int main ( ) { float R = 4 ; cout << cyl ( R ) << endl ; return 0 ; }
Longest rod that can be inserted within a right circular cylinder | C ++ Program to find the longest rod that can be fit within a right circular cylinder ; Function to find the side of the cube ; height and radius cannot be negative ; length of rod ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float rod ( float h , float r ) { if ( h < 0 && r < 0 ) return -1 ; float l = sqrt ( pow ( h , 2 ) + 4 * pow ( r , 2 ) ) ; return l ; } int main ( ) { float h = 4 , r = 1.5 ; cout << rod ( h , r ) << endl ; return 0 ; }
Largest cube that can be inscribed within a right circular cone | C ++ Program to find the biggest cube inscribed within a right circular cone ; Function to find the side of the cube ; height and radius cannot be negative ; side of the cube ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float cubeSide ( float h , float r ) { if ( h < 0 && r < 0 ) return -1 ; float a = ( h * r * sqrt ( 2 ) ) / ( h + sqrt ( 2 ) * r ) ; return a ; } int main ( ) { float h = 5 , r = 6 ; cout << cubeSide ( h , r ) << endl ; return 0 ; }
Largest right circular cone that can be inscribed within a sphere | C ++ Program to find the biggest cone that can be inscribed within a sphere ; Function to find the radius of the cone ; radius cannot be negative ; radius of the cone ; Function to find the height of the cone ; side cannot be negative ; height of the cone ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float coner ( float R ) { if ( R < 0 ) return -1 ; float r = ( 2 * sqrt ( 2 ) * R ) / 3 ; return r ; } float coneh ( float R ) { if ( R < 0 ) return -1 ; float h = ( 4 * R ) / 3 ; return h ; } int main ( ) { float R = 10 ; cout << " r ▁ = ▁ " << coner ( R ) << " , ▁ " << " h ▁ = ▁ " << coneh ( R ) << endl ; return 0 ; }
Largest cone that can be inscribed within a cube | C ++ Program to find the biggest cone inscribed within a cube ; Function to find the radius of the cone ; side cannot be negative ; radius of the cone ; Function to find the height of the cone ; side cannot be negative ; height of the cone ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float coneRadius ( float a ) { if ( a < 0 ) return -1 ; float r = a / sqrt ( 2 ) ; return r ; } float coneHeight ( float a ) { if ( a < 0 ) return -1 ; float h = a ; return h ; } int main ( ) { float a = 6 ; cout << " r ▁ = ▁ " << coneRadius ( a ) << " , ▁ " << " h ▁ = ▁ " << coneHeight ( a ) << endl ; return 0 ; }
Largest cube that can be inscribed within the sphere | C ++ Program to find the biggest cube inscribed within a sphere ; Function to find the side of the cube ; radius cannot be negative ; side of the cube ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float largestCube ( float r ) { if ( r < 0 ) return -1 ; float a = ( 2 * r ) / sqrt ( 3 ) ; return a ; } int main ( ) { float r = 5 ; cout << largestCube ( r ) << endl ; return 0 ; }
Largest sphere that can be inscribed inside a cube | C ++ Program to find the biggest sphere inscribed within a cube ; Function to find the radius of the sphere ; side cannot be negative ; radius of the sphere ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float sphere ( float a ) { if ( a < 0 ) return -1 ; float r = a / 2 ; return r ; } int main ( ) { float a = 5 ; cout << sphere ( a ) << endl ; return 0 ; }
Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts | C ++ implementation of above approach ; function that calculates the maximum no . of cuts ; Driver Code ; Calling function .
#include <bits/stdc++.h> NEW_LINE using namespace std ; int numberOfCuts ( int M , int N ) { int result = 0 ; result = ( M - 1 ) * ( N - 1 ) ; return result ; } int main ( ) { int M = 4 , N = 4 ; int Cuts = numberOfCuts ( M , N ) ; cout << " Maximum ▁ cuts ▁ = ▁ " << Cuts ; return 0 ; }
Find maximum volume of a cuboid from the given perimeter and area | C ++ implementation of the above approach ; function to return maximum volume ; calculate length ; calculate volume ; return result ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; float maxVol ( float P , float A ) { float l = ( P - sqrt ( P * P - 24 * A ) ) / 12 ; float V = l * ( A / 2.0 - l * ( P / 4.0 - l ) ) ; return V ; } int main ( ) { float P = 20 , A = 16 ; cout << maxVol ( P , A ) ; return 0 ; }
Program to calculate area and perimeter of a rhombus whose diagonals are given | C ++ Program to calculate area and perimeter of a rhombus using diagonals ; calculate area and perimeter of a rhombus ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int rhombusAreaPeri ( int d1 , int d2 ) { long long int area , perimeter ; area = ( d1 * d2 ) / 2 ; perimeter = 2 * sqrt ( pow ( d1 , 2 ) + pow ( d2 , 2 ) ) ; cout << " The ▁ area ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " << d1 << " ▁ and ▁ " << d2 << " ▁ is ▁ " << area << " . " << endl ; cout << " The ▁ perimeter ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " << d1 << " ▁ and ▁ " << d2 << " ▁ is ▁ " << perimeter << " . " << endl ; } int main ( ) { int d1 = 2 , d2 = 4 ; rhombusAreaPeri ( d1 , d2 ) ; return 0 ; }
Area of decagon inscribed within the circle | C ++ Program to find the area of the decagon inscribed within a circle ; Function to find the area of the decagon ; radius cannot be negative ; area of the decagon ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float area ( float r ) { if ( r < 0 ) return -1 ; float area = ( 5 * pow ( r , 2 ) * ( 3 - sqrt ( 5 ) ) * ( sqrt ( 5 ) + ( 2 * sqrt ( 5 ) ) ) ) / 4 ; return area ; } int main ( ) { float r = 8 ; cout << area ( r ) << endl ; return 0 ; }
Maximum area of rectangle possible with given perimeter | C ++ to find maximum area rectangle ; Function to find max area ; return area ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxArea ( float perimeter ) { int length = ( int ) ceil ( perimeter / 4 ) ; int breadth = ( int ) floor ( perimeter / 4 ) ; return length * breadth ; } int main ( ) { float n = 38 ; cout << " Maximum ▁ Area ▁ = ▁ " << maxArea ( n ) ; return 0 ; }
Find the foot of perpendicular of a point in a 3 D plane | C ++ program to find foot of perpendicular of a point in a 3 D plane . ; Function to find foot of perpendicular ; Driver Code ; function call
#include <bits/stdc++.h> NEW_LINE #include <iomanip> NEW_LINE #include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void foot ( 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 ; std :: cout << std :: fixed ; std :: cout << std :: setprecision ( 1 ) ; cout << " ▁ x2 ▁ = ▁ " << x2 ; cout << " ▁ y2 ▁ = ▁ " << y2 ; cout << " ▁ z2 ▁ = ▁ " << z2 ; } int main ( ) { float a = 1 ; float b = -2 ; float c = 0 ; float d = 0 ; float x1 = -1 ; float y1 = 3 ; float z1 = 4 ; foot ( a , b , c , d , x1 , y1 , z1 ) ; return 0 ; }
Equation of parabola from its focus and directrix | C ++ program to find equation of a parbola using focus and directrix . ; Function to find equation of parabola . ; Driver Code
#include <bits/stdc++.h> NEW_LINE #include <iomanip> NEW_LINE #include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void equation_parabola ( float x1 , float y1 , float a , float b , float c ) { float t = a * a + b * b ; float a1 = t - ( a * a ) ; float b1 = t - ( b * b ) ; float c1 = ( -2 * t * x1 ) - ( 2 * c * a ) ; float d1 = ( -2 * t * y1 ) - ( 2 * c * b ) ; float e1 = -2 * a * b ; float f1 = ( - c * c ) + ( t * x1 * x1 ) + ( t * y1 * y1 ) ; std :: cout << std :: fixed ; std :: cout << std :: setprecision ( 1 ) ; cout << " equation ▁ of ▁ parabola ▁ is ▁ " << a1 << " ▁ x ^ 2 ▁ + ▁ " << b1 << " ▁ y ^ 2 ▁ + ▁ " << c1 << " ▁ x ▁ + ▁ " << d1 << " ▁ y ▁ + ▁ " << e1 << " ▁ xy ▁ + ▁ " << f1 << " ▁ = ▁ 0 . " ; } int main ( ) { float x1 = 0 ; float y1 = 0 ; float a = 3 ; float b = -4 ; float c = 2 ; equation_parabola ( x1 , y1 , a , b , c ) ; return 0 ; }
Minimum squares to evenly cut a rectangle | CPP program to find minimum number of squares to make a given rectangle . ; if we take gcd ( l , w ) , this will be largest possible side for square , hence minimum number of square . ; Number of squares . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countRectangles ( int l , int w ) { int squareSide = __gcd ( l , w ) ; return ( l * w ) / ( squareSide * squareSide ) ; } int main ( ) { int l = 4 , w = 6 ; cout << countRectangles ( l , w ) << endl ; return 0 ; }
Equation of circle from center and radius | CPP program to find the equation of circle . ; Function to find the equation of circle ; Printing result ; Driver code
#include <iostream> NEW_LINE using namespace std ; void circle_equation ( double x1 , double y1 , double r ) { double a = -2 * x1 ; double b = -2 * y1 ; double c = ( r * r ) - ( x1 * x1 ) - ( y1 * y1 ) ; cout << " x ^ 2 ▁ + ▁ ( " << a << " ▁ x ) ▁ + ▁ " ; cout << " y ^ 2 ▁ + ▁ ( " << b << " ▁ y ) ▁ = ▁ " ; cout << c << " . " << endl ; } int main ( ) { double x1 = 2 , y1 = -3 , r = 8 ; circle_equation ( x1 , y1 , r ) ; return 0 ; }
Program to find the Area and Perimeter of a Semicircle | C ++ program to find the Area and Perimeter of a Semicircle ; Function for calculating the area ; Formula for finding the area ; Function for calculating the perimeter ; Formula for finding the perimeter ; driver code ; Get the radius ; Find the area ; Find the perimeter
#include <iostream> NEW_LINE using namespace std ; float area ( float r ) { return ( 0.5 ) * ( 3.14 ) * ( r * r ) ; } float perimeter ( float r ) { return ( 3.14 ) * ( r ) ; } int main ( ) { int r = 10 ; cout << " The ▁ Area ▁ of ▁ Semicircle : ▁ " << area ( r ) << endl ; cout << " The ▁ Perimeter ▁ of ▁ Semicircle : ▁ " << perimeter ( r ) << endl ; return 0 ; }
Check if the given vectors are at equilibrium or not | CPP program to check the equilibrium of three vectors ; Function to check the equilibrium of three vectors ; summing the x coordinates ; summing the y coordinates ; summing the z coordinates ; Checking the condition for equilibrium ; Driver code ; Checking for equilibrium
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkEquilibrium ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 , int x3 , int y3 , int z3 ) { int resx = x1 + x2 + x3 ; int resy = y1 + y2 + y3 ; int resz = z1 + z2 + z3 ; if ( resx == 0 and resy == 0 and resz == 0 ) return true ; else return false ; } int main ( ) { int x1 = -2 , y1 = -7 , z1 = -9 , x2 = 5 , y2 = -14 , z2 = 14 , x3 = -3 , y3 = 21 , z3 = -5 ; if ( checkEquilibrium ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) ) cout << " The ▁ vectors ▁ are ▁ at ▁ equilibrium . " ; else cout << " The ▁ vectors ▁ are ▁ not ▁ at ▁ equilibrium . " ; return 0 ; }
Find Tangent at a given point on the curve | C ++ program for find Tangent on a curve at given point ; function for find Tangent ; differentiate given equation ; check that point on the curve or not ; if differentiate is negative ; differentiate is positive ; differentiate is zero ; Driver code ; declare variable ; call function findTangent
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findTangent ( int A , int x , int y ) { int dif = A - x * 2 ; if ( y == ( 2 * x - x * x ) ) { if ( dif < 0 ) cout << " y ▁ = ▁ " << dif << " x " << ( x * dif ) + ( y ) ; else if ( dif > 0 ) cout << " y ▁ = ▁ " << dif << " x + " << - x * dif + y ; else cout << " Not ▁ possible " ; } } int main ( ) { int A = 2 , x = 2 , y = 0 ; findTangent ( A , x , y ) ; return 0 ; }
Find Four points such that they form a square whose sides are parallel to x and y axes | C ++ implemenataion of the above approach ; find the largest square ; map to store which points exist ; mark the available points ; a nested loop to choose the opposite corners of square ; remove the chosen point ; remove the chosen point ; check if the other two points exist ; if the square is largest then store it ; add the removed point ; add the removed point ; display the largest square ; Driver code ; given points ; find the largest square
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findLargestSquare ( long long int points [ ] [ 2 ] , int n ) { map < pair < long long int , long long int > , int > m ; for ( int i = 0 ; i < n ; i ++ ) { m [ make_pair ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] ++ ; } long long int side = -1 , x = -1 , y = -1 ; for ( int i = 0 ; i < n ; i ++ ) { m [ make_pair ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] -- ; for ( int j = 0 ; j < n ; j ++ ) { m [ make_pair ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] -- ; if ( i != j && ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) == ( points [ i ] [ 1 ] - points [ j ] [ 1 ] ) ) { if ( m [ make_pair ( points [ i ] [ 0 ] , points [ j ] [ 1 ] ) ] > 0 && m [ make_pair ( points [ j ] [ 0 ] , points [ i ] [ 1 ] ) ] > 0 ) { if ( side < abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) || ( side == abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) && ( ( points [ i ] [ 0 ] * points [ i ] [ 0 ] + points [ i ] [ 1 ] * points [ i ] [ 1 ] ) < ( x * x + y * y ) ) ) ) { x = points [ i ] [ 0 ] ; y = points [ i ] [ 1 ] ; side = abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) ; } } } m [ make_pair ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] ++ ; } m [ make_pair ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] ++ ; } if ( side != -1 ) cout << " Side ▁ of ▁ the ▁ square ▁ is ▁ : ▁ " << side << " points of the square are " ▁ < < ▁ x ▁ < < ▁ " , " ▁ < < ▁ y << " ▁ " << ( x + side ) << " , ▁ " << y << " ▁ " << ( x ) << " , ▁ " << ( y + side ) << " ▁ " << ( x + side ) << " , ▁ " << ( y + side ) << endl ; else cout < < " No ▁ such ▁ square " << endl ; } int main ( ) { int n = 6 ; long long int points [ n ] [ 2 ] = { { 1 , 1 } , { 4 , 4 } , { 3 , 4 } , { 4 , 3 } , { 1 , 4 } , { 4 , 1 } } ; findLargestSquare ( points , n ) ; return 0 ; }
Find length of Diagonal of Hexagon | C ++ Program to find the diagonal of the hexagon ; Function to find the diagonal of the hexagon ; side cannot be negative ; diagonal of the hexagon ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float hexadiagonal ( float a ) { if ( a < 0 ) return -1 ; return 2 * a ; } int main ( ) { float a = 4 ; cout << hexadiagonal ( a ) << endl ; return 0 ; }
Program to find the side of the Octagon inscribed within the square | C ++ Program to find the side of the octagon which can be inscribed within the square ; Function to find the side of the octagon ; side cannot be negative ; side of the octagon ; Driver code ; Get he square side ; Find the side length of the square
#include <bits/stdc++.h> NEW_LINE using namespace std ; float octaside ( float a ) { if ( a < 0 ) return -1 ; float s = a / ( sqrt ( 2 ) + 1 ) ; return s ; } int main ( ) { float a = 4 ; cout << octaside ( a ) << endl ; return 0 ; }
Check whether it is possible to join two points given on circle such that distance between them is k | C ++ program to implement above approach ; Return distance between the centers ; Distance between centers ; Case 5 ; SubCase 1 ; Subcase 2 ; Case 1 ; Case 3 ; Case 4 ; Case 2 ; Since value of k will always be an integer ; Driver Code
#include <bits/stdc++.h> NEW_LINE #define ll long long int NEW_LINE using namespace std ; struct t { ll x , y , r ; } ; typedef struct t node ; long double dis ( ll x1 , ll y1 , ll x2 , ll y2 ) { return sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ; } bool check ( node c1 , node c2 , int k ) { long double min = 0 ; long double max = 0 ; long double de = dis ( c1 . x , c1 . y , c2 . x , c2 . y ) ; if ( de == 0 ) { if ( c1 . r == c2 . r ) { min = 0 ; max = 0 ; } else { if ( c1 . r - c2 . r > 0 ) { min = c1 . r - c2 . r ; max = min + 2 * c2 . r ; } else { min = c2 . r - c1 . r ; max = min + 2 * c1 . r ; } } } else if ( de >= c1 . r + c2 . r ) { min = de - c1 . r - c2 . r ; max = de + c1 . r + c2 . r ; } else if ( de + c2 . r < c1 . r ) { max = c2 . r + c1 . r + de ; min = c1 . r - de - c2 . r ; } else if ( de + c1 . r < c2 . r ) { max = c2 . r + c1 . r + de ; min = c2 . r - de - c1 . r ; } else if ( ( de + c2 . r >= c1 . r ) || ( de + c1 . r >= c2 . r ) ) { max = c2 . r + c1 . r + de ; min = 0 ; } ll temin = ( ll ) ( ceil ( min ) ) ; ll re = ( ll ) max ; if ( k >= temin && k <= re ) return true ; return false ; } int main ( ) { node circle1 , circle2 ; int k = 3 ; circle1 . x = 0 ; circle1 . y = 0 ; circle1 . r = 5 ; circle2 . x = 8 ; circle2 . y = 3 ; circle2 . r = 2 ; if ( check ( circle1 , circle2 , k ) ) cout << " YES " << endl ; else cout << " NO " << endl ; }
Check if it is possible to move from ( 0 , 0 ) to ( x , y ) in N steps | CPP program to check whether it is possible or not to move from ( 0 , 0 ) to ( x , y ) in exactly n steps ; Function to check whether it is possible or not to move from ( 0 , 0 ) to ( x , y ) in exactly n steps ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool Arrive ( int a , int b , int n ) { if ( n >= abs ( a ) + abs ( b ) and ( n - ( abs ( a ) + abs ( b ) ) ) % 2 == 0 ) return true ; return false ; } int main ( ) { int a = 5 , b = 5 , n = 11 ; if ( Arrive ( a , b , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
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 ; }
Number of quadrilaterals possible from the given points | C ++ implementation of above approach ; struct Point points ; determines the orientation of points ; check whether the distinct line segments intersect ; check if points overlap ( similar ) ; it is same , we are returning false because quadrilateral is not possible in this case ; it is not same , So there is a possibility of a quadrilateral ; check for collinearity ; it is collinear , we are returning false because quadrilateral is not possible in this case ; it is not collinear , So there is a possibility of a quadrilateral ; check if any of the points are same ; similar points exist ; check for collinearity ; points are collinear ; * * Checking for cases where no of quadrilaterals = 1 or 3 * * ; Driver code ; A = ( 0 , 9 ) , B = ( - 1 , 0 ) , C = ( 5 , - 1 ) , D = ( 5 , 9 ) ; A = ( 0 , 9 ) , B = ( - 1 , 0 ) , C = ( 5 , - 1 ) , D = ( 0 , 3 ) ; A = ( 0 , 9 ) , B = ( 0 , 10 ) , C = ( 0 , 11 ) , D = ( 0 , 12 ) ; A = ( 0 , 9 ) , B = ( 0 , 9 ) , C = ( 5 , - 1 ) , D = ( 0 , 3 )
#include <iostream> NEW_LINE using namespace std ; { int x ; int y ; } ; int orientation ( Point p , Point q , Point r ) { int val = ( q . y - p . y ) * ( r . x - q . x ) - ( q . x - p . x ) * ( r . y - q . y ) ; if ( val == 0 ) return 0 ; return ( val > 0 ) ? 1 : 2 ; } bool doIntersect ( Point p1 , Point q1 , Point p2 , Point q2 ) { int o1 = orientation ( p1 , q1 , p2 ) ; int o2 = orientation ( p1 , q1 , q2 ) ; int o3 = orientation ( p2 , q2 , p1 ) ; int o4 = orientation ( p2 , q2 , q1 ) ; if ( o1 != o2 && o3 != o4 ) return true ; return false ; } bool similar ( Point p1 , Point p2 ) { if ( p1 . x == p2 . x && p1 . y == p2 . y ) return false ; return true ; } bool collinear ( Point p1 , Point p2 , Point p3 ) { int x1 = p1 . x , y1 = p1 . y ; int x2 = p2 . x , y2 = p2 . y ; int x3 = p3 . x , y3 = p3 . y ; if ( ( y3 - y2 ) * ( x2 - x1 ) == ( y2 - y1 ) * ( x3 - x2 ) ) return false ; else return true ; } int no_of_quads ( Point p1 , Point p2 , Point p3 , Point p4 ) { bool same = true ; same = same & similar ( p1 , p2 ) ; same = same & similar ( p1 , p3 ) ; same = same & similar ( p1 , p4 ) ; same = same & similar ( p2 , p3 ) ; same = same & similar ( p2 , p4 ) ; same = same & similar ( p3 , p4 ) ; if ( same == false ) return 0 ; bool coll = true ; coll = coll & collinear ( p1 , p2 , p3 ) ; coll = coll & collinear ( p1 , p2 , p4 ) ; coll = coll & collinear ( p1 , p3 , p4 ) ; coll = coll & collinear ( p2 , p3 , p4 ) ; if ( coll == false ) return 0 ; int check = 0 ; if ( doIntersect ( p1 , p2 , p3 , p4 ) ) check = 1 ; if ( doIntersect ( p1 , p3 , p2 , p4 ) ) check = 1 ; if ( doIntersect ( p1 , p2 , p4 , p3 ) ) check = 1 ; if ( check == 0 ) return 3 ; return 1 ; } int main ( ) { struct Point p1 , p2 , p3 , p4 ; p1 . x = 0 , p1 . y = 9 ; p2 . x = -1 , p2 . y = 0 ; p3 . x = 5 , p3 . y = -1 ; p4 . x = 5 , p4 . y = 9 ; cout << no_of_quads ( p1 , p2 , p3 , p4 ) << endl ; p1 . x = 0 , p1 . y = 9 ; p2 . x = -1 , p2 . y = 0 ; p3 . x = 5 , p3 . y = -1 ; p4 . x = 0 , p4 . y = 3 ; cout << no_of_quads ( p1 , p2 , p3 , p4 ) << endl ; p1 . x = 0 , p1 . y = 9 ; p2 . x = 0 , p2 . y = 10 ; p3 . x = 0 , p3 . y = 11 ; p4 . x = 0 , p4 . y = 12 ; cout << no_of_quads ( p1 , p2 , p3 , p4 ) << endl ; p1 . x = 0 , p1 . y = 9 ; p2 . x = 0 , p2 . y = 9 ; p3 . x = 5 , p3 . y = -1 ; p4 . x = 0 , p4 . y = 3 ; cout << no_of_quads ( p1 , p2 , p3 , p4 ) << endl ; 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 ; }