codeparrot/xlcost-text-to-code huggingface dataset:
Number of ways to choose K intersecting line segments on X | C ++ program to find Number of ways to choose K intersecting line segments on X - axis ; Function to find ( a ^ b ) % mod in log b ; Till power becomes 0 ; If power is odd ; Multiply base ; Divide power by 1 ; Function to find nCk ; Base case ; Apply formula to find nCk ; Function to find the number of ways ; sort the given lines ; Find the number of total case ; Declare a multiset ; loop till N ; Check if smallest element is smaller than lines [ i ] ; Erase first element ; Exclude the odd cases ; Modulus operation ; Insert into multiset ; Function to precompute factorial and inverse ; Pre - compute factorial and inverse ; Driver code ; Function to pre - compute factorial and inverse
#include <bits/stdc++.h> NEW_LINE using namespace std ; const long long mod = 1000000007 ; const int MAXN = 1001 ; long long factorial [ MAXN ] , inverse [ MAXN ] ; long long power ( long long a , long long b ) { long long res = 1 ; while ( b > 0 ) { if ( b % 2 == 1 ) { res = ( res * a ) % mod ; } a = ( a * a ) % mod ; b >>= 1 ; } return res ; } long long nCk ( int n , int k ) { if ( k < 0 k > n ) { return 0 ; } long long ans = factorial [ n ] ; ans = ( ans * inverse [ n - k ] ) % mod ; ans = ( ans * inverse [ k ] ) % mod ; return ans ; } void numberOfWays ( vector < pair < int , int > > lines , int K , int N ) { sort ( lines . begin ( ) , lines . end ( ) ) ; long long total_case = nCk ( N , K ) ; multiset < int > m ; for ( int i = 0 ; i < N ; i ++ ) { while ( ! m . empty ( ) && ( * m . begin ( ) < lines [ i ] . first ) ) { m . erase ( m . begin ( ) ) ; } total_case -= nCk ( m . size ( ) , K - 1 ) ; total_case += mod ; total_case %= mod ; m . insert ( lines [ i ] . second ) ; } cout << total_case << endl ; } void preCompute ( ) { long long fact = 1 ; factorial [ 0 ] = 1 ; inverse [ 0 ] = 1 ; for ( int i = 1 ; i < MAXN ; i ++ ) { fact = ( fact * i ) % mod ; factorial [ i ] = fact ; inverse [ i ] = power ( factorial [ i ] , mod - 2 ) ; } } int main ( ) { int N = 3 , K = 2 ; vector < pair < int , int > > lines ; preCompute ( ) ; lines . push_back ( { 1 , 3 } ) ; lines . push_back ( { 4 , 5 } ) ; lines . push_back ( { 5 , 7 } ) ; numberOfWays ( lines , K , N ) ; return 0 ; }
Check whether triangle is valid or not if three points are given | C ++ implementation to check if three points form a triangle ; Function to check if three points make a triangle ; Calculation the area of triangle . We have skipped multiplication with 0.5 to avoid floating point computations ; Condition to check if area is not equal to 0 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkTriangle ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { int a = x1 * ( y2 - y3 ) + x2 * ( y3 - y1 ) + x3 * ( y1 - y2 ) ; if ( a == 0 ) cout << " No " ; else cout << " Yes " ; } int main ( ) { int x1 = 1 , x2 = 2 , x3 = 3 , y1 = 1 , y2 = 2 , y3 = 3 ; checkTriangle ( x1 , y1 , x2 , y2 , x3 , y3 ) ; return 0 ; }
Total number of triplets ( A , B , C ) in which the points B and C are Equidistant to A | C ++ implementation to Find the total number of Triplets in which the points are Equidistant ; function to count such triplets ; Iterate over all the points ; Iterate over all points other than the current point ; Compute squared euclidean distance for the current point ; Compute nP2 that is n * ( n - 1 ) ; Return the final result ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int numTrip ( vector < pair < int , int > > & points ) { int res = 0 ; for ( int i = 0 ; i < points . size ( ) ; ++ i ) { unordered_map < long , int > map ( points . size ( ) ) ; for ( int j = 0 ; j < points . size ( ) ; ++ j ) { if ( j == i ) continue ; int dy = points [ i ] . second - points [ j ] . second ; int dx = points [ i ] . first - points [ j ] . first ; int key = dy * dy ; key += dx * dx ; map [ key ] ++ ; } for ( auto & p : map ) res += p . second * ( p . second - 1 ) ; } return res ; } int main ( ) { vector < pair < int , int > > mat = { { 0 , 0 } , { 1 , 0 } , { 2 , 0 } } ; cout << numTrip ( mat ) ; return 0 ; }
Check if any point overlaps the given Circle and Rectangle | C ++ implementation to check if any point overlaps the given circle and rectangle ; Function to check if any point overlaps the given circle and rectangle ; Find the nearest point on the rectangle to the center of the circle ; Find the distance between the nearest point and the center of the circle Distance between 2 points , ( x1 , y1 ) & ( x2 , y2 ) in 2D Euclidean space is ( ( x1 - x2 ) * * 2 + ( y1 - y2 ) * * 2 ) * * 0.5 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkOverlap ( int R , int Xc , int Yc , int X1 , int Y1 , int X2 , int Y2 ) { int Xn = max ( X1 , min ( Xc , X2 ) ) ; int Yn = max ( Y1 , min ( Yc , Y2 ) ) ; int Dx = Xn - Xc ; int Dy = Yn - Yc ; return ( Dx * Dx + Dy * Dy ) <= R * R ; } int main ( ) { int R = 1 ; int Xc = 0 , Yc = 0 ; int X1 = 1 , Y1 = -1 ; int X2 = 3 , Y2 = 1 ; if ( checkOverlap ( R , Xc , Yc , X1 , Y1 , X2 , Y2 ) ) { cout << " True " << endl ; } else { cout << " False " ; } }
Check if the tower of sight issue occurs or not | C ++ program to check if tower of sight issue occurs or not ; Function to check if point p lies in between the line joining p1 and p2 ; If parallel to X - axis ; Point p lies between p1 and p2 ; If parallel to Y - axis ; Point p lies between p1 and p2 ; If point p satisfies the equation of line joining p1 and p2 ; Function to check if tower of sight issue occurred ; B lies between AC ; D lies between AC ; A lies between BD ; C lies between BD ; Driver code ; Point A ; Point B ; Point C ; Point D
#include <bits/stdc++.h> NEW_LINE using namespace std ; int checkIntersection ( pair < int , int > p1 , pair < int , int > p2 , pair < int , int > p ) { int val ; if ( p1 . second == p2 . second && p1 . second == p . second ) { if ( p . first <= max ( p1 . first , p2 . first ) && ( p . first >= min ( p1 . first , p2 . first ) ) ) return 1 ; } if ( p1 . first == p2 . first && p1 . first == p . first ) { if ( p . second <= max ( p1 . second , p2 . second ) && ( p . second >= min ( p1 . second , p2 . second ) ) ) return 1 ; } else { val = ( p . second - p1 . second ) * ( p2 . first - p1 . first ) - ( p . first - p1 . first ) * ( p2 . second - p1 . second ) ; if ( val == 0 ) if ( ( p . first <= max ( p1 . first , p2 . first ) && ( p . first >= min ( p1 . first , p2 . first ) ) ) && ( p . second <= max ( p1 . second , p2 . second ) && ( p . second >= min ( p1 . second , p2 . second ) ) ) ) return 1 ; } return 0 ; } void towerOfSight ( pair < int , int > a , pair < int , int > b , pair < int , int > c , pair < int , int > d ) { int flag = 0 ; if ( checkIntersection ( a , c , b ) ) flag = 1 ; else if ( checkIntersection ( a , c , d ) ) flag = 1 ; else if ( checkIntersection ( b , d , a ) ) flag = 1 ; else if ( checkIntersection ( b , d , c ) ) flag = 1 ; flag ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; } int main ( ) { pair < int , int > a = { 0 , 0 } ; pair < int , int > b = { 0 , -2 } ; pair < int , int > c = { 2 , 0 } ; pair < int , int > d = { 0 , 2 } ; towerOfSight ( a , b , c , d ) ; return 0 ; }
Number of lines from given N points not parallel to X or Y axis | C ++ program to find the number of lines which are formed from given N points and not parallel to X or Y axis ; Function to find the number of lines which are formed from given N points and not parallel to X or Y axis ; This will store the number of points has same x or y coordinates using the map as the value of coordinate can be very large ; Counting frequency of each x and y coordinates ; Total number of pairs can be formed ; We can not choose pairs from these as they have same x coordinatethus they will result line segment parallel to y axis ; we can not choose pairs from these as they have same y coordinate thus they will result line segment parallel to x - axis ; Return the required answer ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int NotParallel ( int p [ ] [ 2 ] , int n ) { map < int , int > x_axis , y_axis ; for ( int i = 0 ; i < n ; i ++ ) { x_axis [ p [ i ] [ 0 ] ] ++ ; y_axis [ p [ i ] [ 1 ] ] ++ ; } int total = ( n * ( n - 1 ) ) / 2 ; for ( auto i : x_axis ) { int c = i . second ; total -= ( c * ( c - 1 ) ) / 2 ; } for ( auto i : y_axis ) { int c = i . second ; total -= ( c * ( c - 1 ) ) / 2 ; } return total ; } int main ( ) { int p [ ] [ 2 ] = { { 1 , 2 } , { 1 , 5 } , { 1 , 15 } , { 2 , 10 } } ; int n = sizeof ( p ) / sizeof ( p [ 0 ] ) ; cout << NotParallel ( p , n ) ; return 0 ; }
Check whether two convex regular polygon have same center or not | C ++ implementation to check whether two convex polygons have same center ; Function to check whether two convex polygons have the same center or not ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int check ( int n , int m ) { if ( m % n == 0 ) { cout << " YES " ; } else { cout << " NO " ; } return 0 ; } int main ( ) { int n = 5 ; int m = 10 ; check ( n , m ) ; return 0 ; }
Modulus of a Complex Number | C ++ program to find the Modulus of a Complex Number ; Function to find modulus of a complex number ; Storing the index of ' + ' ; Storing the index of ' - ' ; Finding the real part of the complex number ; Finding the imaginary part of the complex number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findModulo ( string s ) { int l = s . length ( ) ; int i , modulus = 0 ; if ( s . find ( ' + ' ) < l ) { i = s . find ( ' + ' ) ; } else { i = s . find ( ' - ' ) ; } string real = s . substr ( 0 , i ) ; string imaginary = s . substr ( i + 1 , l - 1 ) ; int x = stoi ( real ) ; int y = stoi ( imaginary ) ; cout << sqrt ( x * x + y * y ) << " STRNEWLINE " ; } int main ( ) { string s = "3 + 4i " ; findModulo ( s ) ; return 0 ; }
Minimum number of blocks required to form Hollow Rectangular Prism | C ++ Implementation to find the minimum no of blocks required to form hollow rectangular prism ; Function to display output ; Function to return minimum no of layers required to form the hollow prism ; Function to calculate no of blocks required for each layer ; No of blocks required for each row ; Check for no of layers is minimum ; Driver function ; Length , width , height of each block ; Side of one wall ; height of each wall
#include <bits/stdc++.h> NEW_LINE using namespace std ; void disp ( int row_no , int block ) { cout << row_no * block ; } int row ( int ht , int h ) { return ht / h ; } void calculate ( int l , int w , int h , int a , int ht ) { int no_block = ( 4 * a ) / l ; int row_no ; if ( h < w ) row_no = row ( ht , w ) ; else row_no = row ( ht , h ) ; disp ( row_no , no_block ) ; } int main ( ) { int l = 50 , w = 20 , h = 35 ; int a = 700 ; int ht = 140 ; calculate ( l , w , h , a , ht ) ; return 0 ; }
Maximum area of rectangle inscribed in an equilateral triangle | CPP implementation to find the maximum area inscribed in an equilateral triangle ; Function to find the maximum area of the rectangle inscribed in an equilateral triangle of side S ; Maximum area of the rectangle inscribed in an equilateral triangle of side S ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double solve ( int s ) { double area = ( 1.732 * pow ( s , 2 ) ) / 8 ; return area ; } int main ( ) { int n = 14 ; cout << solve ( n ) ; }
Area of largest semicircle that can be drawn inside a square | C ++ program to find Area of semicircle in a square ; Function to find area of semicircle ; Driver code ; side of a square ; Call Function to find the area of semicircle
#include <bits/stdc++.h> NEW_LINE using namespace std ; float find_Area ( float a ) { float R = a * ( 2.0 - sqrt ( 2 ) ) ; float area = 3.14 * R * R / 2.0 ; return area ; } int main ( ) { float a = 4 ; cout << " ▁ Area ▁ of ▁ semicircle ▁ = ▁ " << find_Area ( a ) ; return 0 ; }
Count the number of times graph crosses X | C ++ implementation to count the number of times the graph crosses the x - axis . ; Function to to count the number of times the graph crosses the x - axis . ; Iterate over the steps array ; Update the previous level and current level by value given in the steps array ; Condition to check that the graph crosses the origin . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int times ( int steps [ ] , int n ) { int current_level = 0 ; int previous_level = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { previous_level = current_level ; current_level = current_level + steps [ i ] ; if ( ( previous_level < 0 && current_level >= 0 ) || ( previous_level > 0 && current_level <= 0 ) ) { count ++ ; } } return count ; } int main ( ) { int steps [ 12 ] = { 1 , -1 , 0 , 0 , 1 , 1 , -3 , 2 } ; int n = sizeof ( steps ) / sizeof ( int ) ; cout << times ( steps , n ) ; return 0 ; }
Program to find X , Y and Z intercepts of a plane | C ++ program to find the X , Y and Z intercepts of a plane ; For finding the x - intercept put y = 0 and z = 0 ; For finding the y - intercept put x = 0 and z = 0 ; For finding the z - intercept put x = 0 and y = 0 ; For Finding value of A , B , C , D ; Calling the first created function ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float * XandYandZintercept ( float A , float B , float C , float D ) { static float rslt [ 3 ] ; float x = - D / A ; float y = - D / B ; float z = - D / C ; rslt [ 0 ] = x ; rslt [ 1 ] = y ; rslt [ 2 ] = z ; return rslt ; } void equation_plane ( int p [ ] , int q [ ] , int r [ ] ) { int x1 = p [ 0 ] ; int y1 = p [ 1 ] ; int z1 = p [ 2 ] ; int x2 = q [ 0 ] ; int y2 = q [ 1 ] ; int z2 = q [ 2 ] ; int x3 = r [ 0 ] ; int y3 = r [ 1 ] ; int z3 = r [ 2 ] ; 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 ) ; float * rslt = XandYandZintercept ( A , B , C , D ) ; for ( int i = 0 ; i < 3 ; i ++ ) { cout << rslt [ i ] << " ▁ " ; } } int main ( ) { int x1 = -1 ; int y1 = 2 ; int z1 = 1 ; int x2 = 0 ; int y2 = -3 ; int z2 = 2 ; int x3 = 1 ; int y3 = 1 ; int z3 = -4 ; int p [ 3 ] = { x1 , y1 , z1 } ; int q [ 3 ] = { x2 , y2 , z2 } ; int r [ 3 ] = { x3 , y3 , z3 } ; equation_plane ( p , q , r ) ; }
Percentage change in Hemisphere volume if radius is changed | C ++ program to find percentage change in hemisphere volume wrt change in radius ; Function to find the change in hemispheric volume ; Driver code ; Get the change in radius ; Calculate the change in hemispheric volume
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void new_vol ( double x ) { if ( x > 0 ) { cout << " % ▁ change ▁ in ▁ the ▁ " << " volume ▁ of ▁ the ▁ hemisphere : ▁ " << pow ( x , 3 ) / 10000 + 3 * x + ( 3 * pow ( x , 2 ) ) / 100 << " % " << " ▁ increase STRNEWLINE " ; } else if ( x < 0 ) { cout << " % ▁ change ▁ in ▁ the ▁ " << " volume ▁ of ▁ the ▁ hemisphere : ▁ " << pow ( x , 3 ) / 10000 + 3 * x + ( 3 * pow ( x , 2 ) ) / 100 << " % ▁ decrease STRNEWLINE " ; } else { cout << " Volume ▁ remains ▁ the ▁ same . " ; } } int main ( ) { double x = -10.0 ; new_vol ( x ) ; return 0 ; }
Find the integer points ( x , y ) with Manhattan distance atleast N | C ++ code to Find the integer points ( x , y ) with Manhattan distance atleast N ; C ++ function to find all possible point ; Find all 4 corners of the square whose side length is n ; If n is even then the middle point of the square will be an integer , so we will take that point ; Driver Code ; Printing all possible points
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < pair < int , int > > FindPoints ( int n ) { vector < pair < int , int > > v ; v . push_back ( { 0 , 0 } ) ; v . push_back ( { 0 , n } ) ; v . push_back ( { n , 0 } ) ; v . push_back ( { n , n } ) ; if ( n % 2 == 0 ) v . push_back ( { n / 2 , n / 2 } ) ; return v ; } int main ( ) { int N = 8 ; vector < pair < int , int > > v = FindPoints ( N ) ; for ( auto i : v ) { cout << " ( " << i . first << " , ▁ " << i . second << " ) ▁ " ; } return 0 ; }
Find if the glass will be empty or not when the rate of drinking is given | C ++ implementation of the approach ; Function to return the time when the glass will be empty ; Check the condition when the glass will never be empty ; Find the time ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double pie = 3.1415926535897 ; double findsolution ( double d , double h , double m , double n ) { double k = ( 4 * m ) / ( pie * d * d ) ; if ( n > k ) return -1 ; double ans = ( h / ( k - n ) ) ; return ans ; } int main ( ) { double d = 1 , h = 1 , m = 1 , n = 1 ; cout << findsolution ( d , h , m , n ) ; return 0 ; }
Sum of internal angles of a Polygon | C ++ implementation of the approach ; Function to return the sum of internal angles of an n - sided polygon ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sumOfInternalAngles ( int n ) { if ( n < 3 ) return 0 ; return ( n - 2 ) * 180 ; } int main ( ) { int n = 5 ; cout << sumOfInternalAngles ( n ) ; return 0 ; }
Number of ways N can be divided into four parts to construct a rectangle | C ++ implementation of the approach ; Function to return the required number of ways ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int cntWays ( int n ) { if ( n % 2 == 1 ) { return 0 ; } else { return ( n - 2 ) / 4 ; } } int main ( ) { int n = 18 ; cout << cntWays ( n ) ; return 0 ; }
Forming triangles using points on a square | C ++ implementation of the approach ; Function to return the count of possible triangles ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int noOfTriangles ( int n ) { int y = 4 * n ; return ( ( y * ( y - 2 ) * ( y - 1 ) ) - ( 4 * n * ( n - 2 ) * ( n - 1 ) ) ) / 6 ; } int main ( ) { int n = 1 ; cout << noOfTriangles ( n ) ; return 0 ; }
Angle subtended by an arc at the centre of a circle | C ++ implementation of the approach ; Function to find Angle subtended by an arc at the centre of a circle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int angle ( int n ) { return 2 * n ; } int main ( ) { int n = 30 ; cout << angle ( n ) ; return 0 ; }
Check if two given Circles are Orthogonal or not | C ++ program to check if two circles are orthogonal or not ; Function to Check if the given circles are orthogonal ; calculating the square of the distance between C1 and C2 ; Check if the given circles are orthogonal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool orthogonality ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) { int dsquare = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ; if ( dsquare == r1 * r1 + r2 * r2 ) return true ; else return false ; } int main ( ) { int x1 = 4 , y1 = 3 ; int x2 = 0 , y2 = 1 ; int r1 = 2 , r2 = 4 ; bool f = orthogonality ( x1 , y1 , x2 , y2 , r1 , r2 ) ; if ( f ) cout << " Given ▁ circles ▁ are " << " ▁ orthogonal . " ; else cout << " Given ▁ circles ▁ are " << " ▁ not ▁ orthogonal . " ; return 0 ; }
Check if a right | C ++ implementation of the above approach ; Storing all the possible changes to make the triangle right - angled ; Function to check if the triangle is right - angled or not ; Function to check if the triangle can be transformed to right - angled ; Boolean variable to return true or false ; If it is already right - angled ; Applying the changes on the co - ordinates ; Applying on the first co - ordinate ; Applying on the second co - ordinate ; Applying on the third co - ordinate ; If can 't be transformed ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int dx [ ] = { -1 , 0 , 1 , 0 } ; int dy [ ] = { 0 , 1 , 0 , -1 } ; int ifRight ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { int a = ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) ; int b = ( ( x1 - x3 ) * ( x1 - x3 ) ) + ( ( y1 - y3 ) * ( y1 - y3 ) ) ; int c = ( ( x2 - x3 ) * ( x2 - x3 ) ) + ( ( y2 - y3 ) * ( y2 - y3 ) ) ; if ( ( a == ( b + c ) && a != 0 && b != 0 && c != 0 ) || ( b == ( a + c ) && a != 0 && b != 0 && c != 0 ) || ( c == ( a + b ) && a != 0 && b != 0 && c != 0 ) ) { return 1 ; } return 0 ; } void isValidCombination ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { int x , y ; bool possible = 0 ; if ( ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) ) { cout << " ALREADY ▁ RIGHT ▁ ANGLED " ; return ; } else { for ( int i = 0 ; i < 4 ; i ++ ) { x = dx [ i ] + x1 ; y = dy [ i ] + y1 ; if ( ifRight ( x , y , x2 , y2 , x3 , y3 ) ) { cout << " POSSIBLE " ; return ; } x = dx [ i ] + x2 ; y = dy [ i ] + y2 ; if ( ifRight ( x1 , y1 , x , y , x3 , y3 ) ) { cout << " POSSIBLE " ; return ; } x = dx [ i ] + x3 ; y = dy [ i ] + y3 ; if ( ifRight ( x1 , y1 , x2 , y2 , x , y ) ) { cout << " POSSIBLE " ; return ; } } } if ( ! possible ) cout << " NOT ▁ POSSIBLE " << endl ; } int main ( ) { int x1 = -49 , y1 = 0 ; int x2 = 0 , y2 = 50 ; int x3 = 0 , y3 = -50 ; isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 ) ; return 0 ; }
Program to find Area of Triangle inscribed in N | C ++ Program to find the area of a triangle inscribed in N - sided regular polygon ; Function to find the area of the polygon ; area of a regular polygon with N sides and side length len ; Function to find the area of a triangle ; area of one triangle in an N - sided regular polygon ; area of inscribed triangle ; Driver code
#include <bits/stdc++.h> NEW_LINE #include <cmath> NEW_LINE using namespace std ; double area_of_regular_polygon ( double n , double len ) { double P = ( len * n ) ; double A = len / ( 2 * tan ( ( 180 / n ) * 3.14159 / 180 ) ) ; double area = ( P * A ) / 2 ; return area ; } double area_of_triangle_inscribed ( double n , double len ) { double area = area_of_regular_polygon ( n , len ) ; double triangle = area / n ; double ins_tri = ( triangle * 3 ) ; return ins_tri ; } int main ( ) { double n = 6 , len = 10 ; cout << area_of_triangle_inscribed ( n , len ) << endl ; return 0 ; }
Find the area of quadrilateral when diagonal and the perpendiculars to it from opposite vertices are given | C ++ program to find the area of quadrilateral ; Function to find the area of quadrilateral ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float Area ( int d , int h1 , int h2 ) { float area ; area = 0.5 * d * ( h1 + h2 ) ; return area ; } int main ( ) { int d = 6 , h1 = 4 , h2 = 3 ; cout << " Area ▁ of ▁ Quadrilateral ▁ = ▁ " << ( Area ( d , h1 , h2 ) ) ; return 0 ; }
Find the diagonal of the Cube | CPP program to find length of the diagonal of the cube ; Function to find length of diagonal of cube ; Formula to Find length of diagonal of cube ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; float diagonal_length ( float a ) { float L ; L = a * sqrt ( 3 ) ; return L ; } int main ( ) { float a = 5 ; cout << diagonal_length ( a ) ; return 0 ; }
Concentric Hexagonal Numbers | CPP program to find nth concentric hexagon number ; Function to find nth concentric hexagon number ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int concentric_Hexagon ( int n ) { return 3 * pow ( n , 2 ) / 2 ; } int main ( ) { int n = 3 ; cout << concentric_Hexagon ( n ) ; return 0 ; }
Find area of the larger circle when radius of the smaller circle and difference in the area is given | C ++ implementation of the approach ; Function to return the area of the bigger circle ; Find the radius of the bigger circle ; Calculate the area of the bigger circle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const double PI = 3.14 ; double find_area ( int r , int d ) { double R = d / PI ; R += pow ( r , 2 ) ; R = sqrt ( R ) ; double area = PI * pow ( R , 2 ) ; return area ; } int main ( ) { int r = 4 , d = 5 ; cout << find_area ( r , d ) ; return 0 ; }