codeparrot/xlcost-text-to-code huggingface dataset:
Find same contacts in a list of contacts | A C ++ program to find same contacts in a list of contacts ; Structure for storing contact details . ; A utility function to fill entries in adjacency matrix representation of graph ; Initialize the adjacency matrix ; Traverse through all contacts ; Add mat from i to j and vice versa , if possible . Since length of each contact field is at max some constant . ( say 30 ) so body execution of this for loop takes constant time . ; A recuesive function to perform DFS with vertex i as source ; Finds similar contacrs in an array of contacts ; vector for storing the solution ; Declare 2D adjaceny matrix for mats ; visited array to keep track of visited nodes ; Fill adjacency matrix ; Since , we made a graph with contacts as nodes with fields as links . two nodes are linked if they represent the same person . so , total number of connected components and nodes in each component will be our answer . ; Add delimeter to separate nodes of one component from other . ; Print the solution ; Drive Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct contact { string field1 , field2 , field3 ; } ; void buildGraph ( contact arr [ ] , int n , int * mat [ ] ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) mat [ i ] [ j ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] . field1 == arr [ j ] . field1 arr [ i ] . field1 == arr [ j ] . field2 arr [ i ] . field1 == arr [ j ] . field3 arr [ i ] . field2 == arr [ j ] . field1 arr [ i ] . field2 == arr [ j ] . field2 arr [ i ] . field2 == arr [ j ] . field3 arr [ i ] . field3 == arr [ j ] . field1 arr [ i ] . field3 == arr [ j ] . field2 arr [ i ] . field3 == arr [ j ] . field3 ) { mat [ i ] [ j ] = 1 ; mat [ j ] [ i ] = 1 ; break ; } } } void DFSvisit ( int i , int * mat [ ] , bool visited [ ] , vector < int > & sol , int n ) { visited [ i ] = true ; sol . push_back ( i ) ; for ( int j = 0 ; j < n ; j ++ ) if ( mat [ i ] [ j ] && ! visited [ j ] ) DFSvisit ( j , mat , visited , sol , n ) ; } void findSameContacts ( contact arr [ ] , int n ) { vector < int > sol ; int * * mat = new int * [ n ] ; for ( int i = 0 ; i < n ; i ++ ) mat [ i ] = new int [ n ] ; bool visited [ n ] ; memset ( visited , 0 , sizeof ( visited ) ) ; buildGraph ( arr , n , mat ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! visited [ i ] ) { DFSvisit ( i , mat , visited , sol , n ) ; sol . push_back ( -1 ) ; } } for ( int i = 0 ; i < sol . size ( ) ; i ++ ) if ( sol [ i ] == -1 ) cout << endl ; else cout << sol [ i ] << " ▁ " ; } int main ( ) { contact arr [ ] = { { " Gaurav " , " gaurav @ gmail . com " , " gaurav @ gfgQA . com " } , { " Lucky " , " lucky @ gmail . com " , " + 1234567" } , { " gaurav123" , " + 5412312" , " gaurav123 @ skype . com " } , { " gaurav1993" , " + 5412312" , " gaurav @ gfgQA . com " } , { " raja " , " + 2231210" , " raja @ gfg . com " } , { " bahubali " , " + 878312" , " raja " } } ; int n = sizeof arr / sizeof arr [ 0 ] ; findSameContacts ( arr , n ) ; return 0 ; }
Area of the biggest ellipse inscribed within a rectangle | C ++ Program to find the biggest ellipse which can be inscribed within the rectangle ; Function to find the area of the ellipse ; The sides cannot be negative ; Area of the ellipse ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float ellipse ( float l , float b ) { if ( l < 0 b < 0 ) return -1 ; float x = ( 3.14 * l * b ) / 4 ; return x ; } int main ( ) { float l = 5 , b = 3 ; cout << ellipse ( l , b ) << endl ; return 0 ; }
Determine the number of squares of unit area that a given line will pass through . |  ; Function to return the required position ; Driver Code
/ * C ++ program to determine the number of squares that line will pass through * #include < bits / stdc ++ . h > using namespace std ; int noOfSquares ( int x1 , int y1 , int x2 , int y2 ) { int dx = abs ( x2 - x1 ) ; int dy = abs ( y2 - y1 ) ; int ans = dx + dy - __gcd ( dx , dy ) ; cout << ans ; } int main ( ) { int x1 = 1 , y1 = 1 , x2 = 4 , y2 = 3 ; noOfSquares ( x1 , y1 , x2 , y2 ) ; return 0 ; }
Count paths with distance equal to Manhattan distance | C ++ implementation of the approach ; Function to return the value of nCk ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; Function to return the number of paths ; Difference between the ' x ' coordinates of the given points ; Difference between the ' y ' coordinates of the given points ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long int NEW_LINE ll binomialCoeff ( int n , int k ) { ll res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } ll countPaths ( int x1 , int y1 , int x2 , int y2 ) { int m = abs ( x1 - x2 ) ; int n = abs ( y1 - y2 ) ; return ( binomialCoeff ( m + n , n ) ) ; } int main ( ) { int x1 = 2 , y1 = 3 , x2 = 4 , y2 = 5 ; cout << countPaths ( x1 , y1 , x2 , y2 ) ; return 0 ; }
Find the area of largest circle inscribed in ellipse | CPP program to find the area of the circle ; Area of the Reuleaux triangle ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define pi  3.1415926 NEW_LINE double areaCircle ( double b ) { double area = pi * b * b ; return area ; } int main ( ) { double a = 10 , b = 8 ; cout << areaCircle ( b ) ; return 0 ; }
Section formula for 3 D | CPP program to find point that divides given line in given ratio in 3D . ; Function to find the section of the line ; Applying section formula ; Printing result ; Driver code
#include <iostream> NEW_LINE using namespace std ; void section ( double x1 , double x2 , double y1 , double y2 , double z1 , double z2 , double m , double n ) { double x = ( ( m * x2 ) + ( n * x1 ) ) / ( m + n ) ; double y = ( ( m * y2 ) + ( n * y1 ) ) / ( m + n ) ; double z = ( ( m * z2 ) + ( n * z1 ) ) / ( m + n ) ; cout << " ( " << x << " , ▁ " ; cout << y << " , ▁ " ; cout << z << " ) " << endl ; } int main ( ) { double x1 = 2 , x2 = 4 , y1 = -1 , y2 = 3 , z1 = 4 , z2 = 2 , m = 2 , n = 3 ; section ( x1 , x2 , y1 , y2 , z1 , z2 , m , n ) ; return 0 ; }
Program to find the Circumcircle of any regular polygon | C ++ Program to find the radius of the circumcircle of the given polygon ; Function to find the radius of the circumcircle ; these cannot be negative ; Radius of the circumcircle ; Return the radius ; Driver code ; Find the radius of the circumcircle
#include <bits/stdc++.h> NEW_LINE using namespace std ; float findRadiusOfcircumcircle ( float n , float a ) { if ( n < 0 a < 0 ) return -1 ; float radius = a / sqrt ( 2 - ( 2 * cos ( 360 / n ) ) ) ; return radius ; } int main ( ) { float n = 5 , a = 6 ; cout << findRadiusOfcircumcircle ( n , a ) << endl ; return 0 ; }
Program to find the Radius of the incircle of the triangle | C ++ Program to find the radius of the incircle of the given triangle ; Function to find the radius of the incircle ; the sides cannot be negative ; semi - perimeter of the circle ; area of the triangle ; Radius of the incircle ; Return the radius ; Driver code ; Get the sides of the triangle ; Find the radius of the incircle
#include <bits/stdc++.h> NEW_LINE using namespace std ; float findRadiusOfIncircle ( float a , float b , float c ) { if ( a < 0 b < 0 c < 0 ) return -1 ; float p = ( a + b + c ) / 2 ; float area = sqrt ( p * ( p - a ) * ( p - b ) * ( p - c ) ) ; float radius = area / p ; return radius ; } int main ( ) { float a = 2 , b = 2 , c = 3 ; cout << findRadiusOfIncircle ( a , b , c ) << endl ; return 0 ; }
Find area of triangle if two vectors of two adjacent sides are given | C ++ program to calculate area of triangle if vectors of 2 adjacent sides are given ; function to calculate area of triangle ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float area ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 ) { float area = sqrt ( pow ( ( y1 * z2 - y2 * z1 ) , 2 ) + pow ( ( x1 * z2 - x2 * z1 ) , 2 ) + pow ( ( x1 * y2 - x2 * y1 ) , 2 ) ) ; area = area / 2 ; return area ; } int main ( ) { int x1 = -2 ; int y1 = 0 ; int z1 = -5 ; int x2 = 1 ; int y2 = -2 ; int z2 = -1 ; float a = area ( x1 , y1 , z1 , x2 , y2 , z2 ) ; cout << " Area ▁ = ▁ " << a << endl ; return 0 ; }
Largest trapezoid that can be inscribed in a semicircle | C ++ Program to find the biggest trapezoid which can be inscribed within the semicircle ; Function to find the area of the biggest trapezoid ; the radius cannot be negative ; area of the trapezoid ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float trapezoidarea ( float r ) { if ( r < 0 ) return -1 ; float a = ( 3 * sqrt ( 3 ) * pow ( r , 2 ) ) / 4 ; return a ; } int main ( ) { float r = 5 ; cout << trapezoidarea ( r ) << endl ; return 0 ; }
Largest rectangle that can be inscribed in a semicircle | C ++ Program to find the the biggest rectangle which can be inscribed within the semicircle ; Function to find the area of the biggest rectangle ; the radius cannot be negative ; area of the rectangle ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float rectanglearea ( float r ) { if ( r < 0 ) return -1 ; float a = r * r ; return a ; } int main ( ) { float r = 5 ; cout << rectanglearea ( r ) << endl ; return 0 ; }
Maximum distinct lines passing through a single point | C ++ program to find maximum number of lines which can pass through a single point ; function to find maximum lines which passes through a single point ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxLines ( int n , int x1 [ ] , int y1 [ ] , int x2 [ ] , int y2 [ ] ) { unordered_set < double > s ; double slope ; for ( int i = 0 ; i < n ; ++ i ) { if ( x1 [ i ] == x2 [ i ] ) slope = INT_MAX ; else slope = ( y2 [ i ] - y1 [ i ] ) * 1.0 / ( x2 [ i ] - x1 [ i ] ) * 1.0 ; s . insert ( slope ) ; } return s . size ( ) ; } int main ( ) { int n = 2 , x1 [ ] = { 1 , 2 } , y1 [ ] = { 1 , 2 } , x2 [ ] = { 2 , 4 } , y2 [ ] = { 2 , 10 } ; cout << maxLines ( n , x1 , y1 , x2 , y2 ) ; return 0 ; }
Find area of parallelogram if vectors of two adjacent sides are given | C ++ code to calculate area of parallelogram if vectors of 2 adjacent sides are given ; Function to calculate area of parallelogram ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float area ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ) { float area = sqrt ( pow ( ( y1 * z2 - y2 * z1 ) , 2 ) + pow ( ( x1 * z2 - x2 * z1 ) , 2 ) + pow ( ( x1 * y2 - x2 * y1 ) , 2 ) ) ; return area ; } int main ( ) { float x1 = 3 ; float y1 = 1 ; float z1 = -2 ; float x2 = 1 ; float y2 = -3 ; float z2 = 4 ; float a = area ( x1 , y1 , z1 , x2 , y2 , z2 ) ; cout << " Area ▁ = ▁ " << a ; return 0 ; }
Maximum possible intersection by moving centers of line segments | Function to print the maximum intersection ; Case 1 ; Case 2 ; Case 3 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int max_intersection ( int * center , int length , int k ) { sort ( center , center + 3 ) ; if ( center [ 2 ] - center [ 0 ] >= 2 * k + length ) { return 0 ; } else if ( center [ 2 ] - center [ 0 ] >= 2 * k ) { return ( 2 * k - ( center [ 2 ] - center [ 0 ] - length ) ) ; } else return length ; } int main ( ) { int center [ 3 ] = { 1 , 2 , 3 } ; int L = 1 ; int K = 1 ; cout << max_intersection ( center , L , K ) ; }
Haversine formula to find distance between two points on a sphere | C ++ program for the haversine formula C ++ program for the haversine formula ; distance between latitudes and longitudes ; convert to radians ; apply formulae ; Driver code
#include <iostream> NEW_LINE #include <cmath> NEW_LINE using namespace std ; static double haversine ( double lat1 , double lon1 , double lat2 , double lon2 ) { double dLat = ( lat2 - lat1 ) * M_PI / 180.0 ; double dLon = ( lon2 - lon1 ) * M_PI / 180.0 ; lat1 = ( lat1 ) * M_PI / 180.0 ; lat2 = ( lat2 ) * M_PI / 180.0 ; double a = pow ( sin ( dLat / 2 ) , 2 ) + pow ( sin ( dLon / 2 ) , 2 ) * cos ( lat1 ) * cos ( lat2 ) ; double rad = 6371 ; double c = 2 * asin ( sqrt ( a ) ) ; return rad * c ; } int main ( ) { double lat1 = 51.5007 ; double lon1 = 0.1246 ; double lat2 = 40.6892 ; double lon2 = 74.0445 ; cout << haversine ( lat1 , lon1 , lat2 , lon2 ) << " ▁ K . M . " ; return 0 ; }
Pentatope number | C ++ Program to find the nth Pentatope Number ; Function that returns nth pentatope number ; Drivers Code ; For 5 th PentaTope Number ; For 11 th PentaTope Number
#include <bits/stdc++.h> NEW_LINE using namespace std ; int pentatopeNum ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) * ( n + 3 ) ) / 24 ; } int main ( ) { int n = 5 ; cout << pentatopeNum ( n ) << endl ; n = 11 ; cout << pentatopeNum ( n ) << endl ; return 0 ; }
Heptagonal number | C ++ program to find the nth Heptagonal number ; Function to return Nth Heptagonal number ; Drivers Code
#include <iostream> NEW_LINE using namespace std ; int heptagonalNumber ( int n ) { return ( ( 5 * n * n ) - ( 3 * n ) ) / 2 ; } int main ( ) { int n = 2 ; cout << heptagonalNumber ( n ) << endl ; n = 15 ; cout << heptagonalNumber ( n ) << endl ; return 0 ; }
Icosidigonal number | C ++ program to find nth Icosidigonal number ; Function to calculate Icosidigonal number ; Formula for finding nth Icosidigonal number ; Driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int icosidigonal_num ( long int n ) { return ( 20 * n * n - 18 * n ) / 2 ; } int main ( ) { long int n = 4 ; cout << n << " th ▁ Icosidigonal ▁ number ▁ : " << icosidigonal_num ( n ) ; cout << endl ; n = 8 ; cout << n << " th ▁ Icosidigonal ▁ number : " << icosidigonal_num ( n ) ; return 0 ; }
Hypercube Graph | C ++ program to find vertices in a hypercube graph of order n ; function to find power of 2 ; driver program
#include <iostream> NEW_LINE using namespace std ; int power ( int n ) { if ( n == 1 ) return 2 ; return 2 * power ( n - 1 ) ; } int main ( ) { int n = 4 ; cout << power ( n ) ; return 0 ; }
Reflection of a point at 180 degree rotation of another point | CPP Program tof find the 180 degree reflection of one point around another point . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findPoint ( int x1 , int y1 , int x2 , int y2 ) { cout << " ( " << 2 * x2 - x1 << " , ▁ " << 2 * y2 - y1 << " ) " ; } int main ( ) { int x1 = 0 , y1 = 0 , x2 = 1 , y2 = 1 ; findPoint ( x1 , y1 , x2 , y2 ) ; return 0 ; }
Program to check if the points are parallel to X axis or Y axis | CPP program to check for parallel to X and Y Axis ; To check for parallel line ; checking for parallel to X and Y axis condition ; To display the output ; Driver 's Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void parallel ( int n , int a [ ] [ 2 ] ) { bool x = true , y = true ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] [ 0 ] != a [ i + 1 ] [ 0 ] ) x = false ; if ( a [ i ] [ 1 ] != a [ i + 1 ] [ 1 ] ) y = false ; } if ( x ) cout << " parallel ▁ to ▁ Y ▁ Axis " << endl ; else if ( y ) cout << " parallel ▁ to ▁ X ▁ Axis " << endl ; else cout << " Not ▁ parallel ▁ to ▁ X " << " ▁ and ▁ Y ▁ Axis " << endl ; } int main ( ) { int a [ ] [ 2 ] = { { 1 , 2 } , { 1 , 4 } , { 1 , 6 } , { 1 , 0 } } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; parallel ( n , a ) ; return 0 ; }
Triangular Matchstick Number | C ++ program to find X - th triangular matchstick number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int numberOfSticks ( int x ) { return ( 3 * x * ( x + 1 ) ) / 2 ; } int main ( ) { cout << numberOfSticks ( 7 ) ; return 0 ; }
Total area of two overlapping rectangles | C ++ program to find total area of two overlapping Rectangles ; Returns Total Area of two overlap rectangles ; Area of 1 st Rectangle ; Area of 2 nd Rectangle ; Length of intersecting part i . e start from max ( l1 . x , l2 . x ) of x - coordinate and end at min ( r1 . x , r2 . x ) x - coordinate by subtracting start from end we get required lengths ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Point { int x , y ; } ; int overlappingArea ( Point l1 , Point r1 , Point l2 , Point r2 ) { int area1 = abs ( l1 . x - r1 . x ) * abs ( l1 . y - r1 . y ) ; int area2 = abs ( l2 . x - r2 . x ) * abs ( l2 . y - r2 . y ) ; int x_dist = min ( r1 . x , r2 . x ) - max ( l1 . x , l2 . x ) ; int y_dist = ( min ( r1 . y , r2 . y ) - max ( l1 . y , l2 . y ) ) ; int areaI = 0 ; if ( x_dist > 0 && y_dist > 0 ) { areaI = x_dist * y_dist ; } return ( area1 + area2 - areaI ) ; } int main ( ) { Point l1 = { 2 , 2 } , r1 = { 5 , 7 } ; Point l2 = { 3 , 4 } , r2 = { 6 , 9 } ; cout << overlappingArea ( l1 , r1 , l2 , r2 ) ; return 0 ; }
Area of square Circumscribed by Circle | C ++ program to find Area of square Circumscribed by Circle ; Function to find area of square ; Driver code ; Radius of a circle ; Call Function to find an area of square
#include <iostream> NEW_LINE using namespace std ; int find_Area ( int r ) { return ( 2 * r * r ) ; } int main ( ) { int r = 3 ; cout << " ▁ Area ▁ of ▁ square ▁ = ▁ " << find_Area ( r ) ; return 0 ; }
Check whether triangle is valid or not if sides are given | C ++ program to check if three sides form a triangle or not ; function to check if three sider form a triangle or not ; check condition ; Driver function ; function calling and print output
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkValidity ( int a , int b , int c ) { if ( a + b <= c a + c <= b b + c <= a ) return false ; else return true ; } int main ( ) { int a = 7 , b = 10 , c = 5 ; if ( checkValidity ( a , b , c ) ) cout << " Valid " ; else cout << " Invalid " ; }
Find the Surface area of a 3D figure | CPP program to find the Surface area of a 3D figure ; Declaring the size of the matrix ; Absolute Difference between the height of two consecutive blocks ; Function To calculate the Total surfaceArea . ; Traversing the matrix . ; If we are traveling the topmost row in the matrix , we declare the wall above it as 0 as there is no wall above it . ; If we are traveling the leftmost column in the matrix , we declare the wall left to it as 0 as there is no wall left it . ; If its not the topmost row ; If its not the leftmost column ; Summing up the contribution of by the current block ; If its the rightmost block of the matrix it will contribute area equal to its height as a wall on the right of the figure ; If its the lowest block of the matrix it will contribute area equal to its height as a wall on the bottom of the figure ; Adding the contribution by the base and top of the figure ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int M = 3 ; const int N = 3 ; int contribution_height ( int current , int previous ) { return abs ( current - previous ) ; } int surfaceArea ( int A [ N ] [ M ] ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int up = 0 ; int left = 0 ; if ( i > 0 ) up = A [ i - 1 ] [ j ] ; if ( j > 0 ) left = A [ i ] [ j - 1 ] ; ans += contribution_height ( A [ i ] [ j ] , up ) + contribution_height ( A [ i ] [ j ] , left ) ; if ( i == N - 1 ) ans += A [ i ] [ j ] ; if ( j == M - 1 ) ans += A [ i ] [ j ] ; } } ans += N * M * 2 ; return ans ; } int main ( ) { int A [ N ] [ M ] = { { 1 , 3 , 4 } , { 2 , 2 , 3 } , { 1 , 2 , 4 } } ; cout << surfaceArea ( A ) << endl ; return 0 ; }
Program to calculate area and volume of a Tetrahedron | C ++ Program to Calculate area of tetrahedron ; Utility Function ; Driver Code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; double area_of_tetrahedron ( int side ) { return ( sqrt ( 3 ) * ( side * side ) ) ; } int main ( ) { int side = 3 ; cout << " Area ▁ of ▁ Tetrahedron ▁ = " << area_of_tetrahedron ( side ) ; }
Program to calculate area and volume of a Tetrahedron | C ++ code to find the volume of a tetrahedron ; Function to calculate volume ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double vol_tetra ( int side ) { double volume = ( pow ( side , 3 ) / ( 6 * sqrt ( 2 ) ) ) ; return volume ; } int main ( ) { int side = 3 ; double vol = vol_tetra ( side ) ; vol = ( double ) round ( vol * 100 ) / 100 ; cout << vol ; return 0 ; }
Program to find slope of a line | C ++ program for slope of line ; function to find the slope of a straight line ; driver code to check the above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; float slope ( float x1 , float y1 , float x2 , float y2 ) { if ( x1 == x2 ) return INT_MAX ; return ( y2 - y1 ) / ( x2 - x1 ) ; } int main ( ) { float x1 = 4 , y1 = 2 ; float x2 = 2 , y2 = 5 ; cout << " Slope ▁ is : ▁ " << slope ( x1 , y1 , x2 , y2 ) ; return 0 ; }
Program to calculate area and perimeter of equilateral triangle | CPP program to find area and perimeter of equilateral triangle ; Function to calculate Area of equilateral triangle ; Function to calculate Perimeter of equilateral triangle ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float area_equi_triangle ( float side ) { return sqrt ( 3 ) / 4 * side * side ; } float peri_equi_triangle ( float side ) { return 3 * side ; } int main ( ) { float side = 4 ; cout << " Area ▁ of ▁ Equilateral ▁ Triangle : ▁ " << area_equi_triangle ( side ) << endl ; cout << " Perimeter ▁ of ▁ Equilateral ▁ Triangle : ▁ " << peri_equi_triangle ( side ) ; return 0 ; }
Maximum integral co | C ++ program to find maximum integral points such that distances between any two is not integer . ; Making set of coordinates such that any two points are non - integral distance apart ; used to avoid duplicates in result ; Driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printSet ( int x , int y ) { set < pair < int , int > > arr ; for ( int i = 0 ; i <= min ( x , y ) ; i ++ ) { pair < int , int > pq ; pq = make_pair ( i , min ( x , y ) - i ) ; arr . insert ( pq ) ; } for ( auto it = arr . begin ( ) ; it != arr . end ( ) ; it ++ ) cout << ( * it ) . first << " ▁ " << ( * it ) . second << endl ; } int main ( ) { int x = 4 , y = 4 ; printSet ( x , y ) ; return 0 ; }
Program for Volume and Surface Area of Cuboid | CPP program to find volume and total surface area of cuboid ; utility function ; driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; double areaCuboid ( double l , double h , double w ) { return ( l * h * w ) ; } double surfaceAreaCuboid ( double l , double h , double w ) { return ( 2 * l * w + 2 * w * h + 2 * l * h ) ; } int main ( ) { double l = 1 ; double h = 5 ; double w = 7 ; cout << " Area ▁ = ▁ " << areaCuboid ( l , h , w ) << endl ; cout << " Total ▁ Surface ▁ Area ▁ = ▁ " << surfaceAreaCuboid ( l , h , w ) ; return 0 ; }
Program to find Circumference of a Circle | CPP program to find circumference of circle ; utility function ; driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define PI  3.1415 NEW_LINE double circumference ( double r ) { double cir = 2 * PI * r ; return cir ; } int main ( ) { double r = 5 ; cout << " Circumference ▁ = ▁ " << circumference ( r ) ; return 0 ; }
Number of rectangles in N * M grid | C ++ program to count number of rectangles in a n x m grid ; driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int rectCount ( int n , int m ) { return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ; } int main ( ) { int n = 5 , m = 4 ; cout << rectCount ( n , m ) ; return 0 ; }
Number of unique rectangles formed using N unit squares | C ++ program to count rotationally equivalent rectangles with n unit squares ; height >= length is maintained ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countRect ( int n ) { int ans = 0 ; for ( int length = 1 ; length <= sqrt ( n ) ; ++ length ) for ( int height = length ; height * length <= n ; ++ height ) ans ++ ; return ans ; } int main ( ) { int n = 5 ; printf ( " % d " , countRect ( n ) ) ; return 0 ; }
Find the Missing Point of Parallelogram | C ++ program to find missing point of a parallelogram ; main method ; coordinates of A ; coordinates of B ; coordinates of C
#include <bits/stdc++.h> NEW_LINE using namespace std ; int main ( ) { int ax = 5 , ay = 0 ; int bx = 1 , by = 1 ; int cx = 2 , cy = 5 ; cout << ax + cx - bx << " , ▁ " << ay + cy - by ; return 0 ; }