codeparrot/xlcost-text-to-code huggingface dataset:
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
using System ; class GFG { static bool check ( long a , long b , long p , long q ) { long 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 ; } static 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 ; } public static void Main ( ) { int a = - 4 , b = - 2 ; int x = 0 , y = 0 ; int p = - 2 , q = - 1 ; if ( check ( a , b , x , y , p , q ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
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
using System ; class GFG { static float trianglearea ( float a , float b ) { if ( a < 0 b < 0 ) return - 1 ; float area = ( float ) ( 3 * Math . Sqrt ( 3 ) * Math . Pow ( a , 2 ) ) / ( 4 * b ) ; return area ; } public static void Main ( ) { float a = 4 , b = 2 ; Console . WriteLine ( trianglearea ( a , b ) ) ; } }
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
using System ; class GFG { static float squarearea ( float a , float b ) { if ( a < 0 b < 0 ) return - 1 ; float area = 4 * ( float ) ( ( Math . Pow ( a , 2 ) + Math . Pow ( b , 2 ) ) / ( Math . Pow ( a , 2 ) * Math . Pow ( b , 2 ) ) ) ; return area ; } public static void Main ( ) { float a = 4 , b = 2 ; Console . WriteLine ( squarearea ( a , b ) ) ; } }
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
using System ; class GFG { static float trianglearea ( float r ) { if ( r < 0 ) return - 1 ; return r * r ; } public static void Main ( ) { float r = 5 ; Console . Write ( trianglearea ( r ) ) ; } }
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
using System ; class GFG { static float squarearea ( float r ) { if ( r < 0 ) return - 1 ; float a = 4 * ( float ) ( Math . Pow ( r , 2 ) / 5 ) ; return a ; } public static void Main ( ) { float r = 5 ; Console . WriteLine ( squarearea ( r ) ) ; } }
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
using System ; class GFG { static float rectanglearea ( float a , float b ) { if ( a < 0 b < 0 ) return - 1 ; return 2 * a * b ; } public static void Main ( ) { float a = 10 , b = 8 ; Console . WriteLine ( rectanglearea ( a , b ) ) ; } }
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
using System ; class GFG { static 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 ; } public static void Main ( ) { float l = 5 , b = 12 , h = 13 ; Console . WriteLine ( squareArea ( l , b , h ) ) ; } }
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
using System ; class GFG { static int MAX = 50 ; static void solveQuery ( int n , int q , int [ ] qi , int [ ] qj ) { int [ ] arr = new int [ 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 ) { Console . Write ( " YES STRNEWLINE " ) ; arr [ qi [ k ] ] = qj [ k ] ; arr [ qj [ k ] ] = qi [ k ] ; } else Console . Write ( " NO STRNEWLINE " ) ; } } public static void 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 ) ; } }
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
using System ; class GFG { static int squares ( int l , int b , int a ) { return ( int ) ( Math . Ceiling ( l / ( double ) a ) * Math . Ceiling ( b / ( double ) a ) ) ; } public static void Main ( ) { int l = 11 , b = 23 , a = 14 ; Console . Write ( squares ( l , b , a ) ) ; } }
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
using System ; class GFG { static 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 ) ; } static int squarearea ( int l , int b ) { if ( l < 0 b < 0 ) return - 1 ; int n = ( l * b ) / gcd ( l , b ) ; return n * n ; } public static void Main ( ) { int l = 6 , b = 4 ; Console . Write ( squarearea ( l , b ) ) ; } }
Find all angles of a triangle in 3D | C # program for finding all angles of a triangle ; function for finding the angle ; Driver code
using System ; class GFG { static double 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 ) ; double den = Math . Sqrt ( Math . Pow ( ( x2 - x1 ) , 2 ) + Math . Pow ( ( y2 - y1 ) , 2 ) + Math . Pow ( ( z2 - z1 ) , 2 ) ) * Math . Sqrt ( Math . Pow ( ( x3 - x1 ) , 2 ) + Math . Pow ( ( y3 - y1 ) , 2 ) + Math . Pow ( ( z3 - z1 ) , 2 ) ) ; double angle = Math . Acos ( num / den ) * ( 180.0 / 3.141592653589793238463 ) ; return angle ; } public static void Main ( ) { int x1 = - 1 , y1 = 3 , z1 = 2 ; int x2 = 2 , y2 = 3 , z2 = 5 ; int x3 = 3 , y3 = 5 , z3 = - 2 ; double angle_A = angle_triangle ( x1 , x2 , x3 , y1 , y2 , y3 , z1 , z2 , z3 ) ; double angle_B = angle_triangle ( x2 , x3 , x1 , y2 , y3 , y1 , z2 , z3 , z1 ) ; double angle_C = angle_triangle ( x3 , x2 , x1 , y3 , y2 , y1 , z3 , z2 , z1 ) ; Console . WriteLine ( " Angles ▁ are ▁ : " ) ; Console . WriteLine ( " angle ▁ A ▁ = ▁ " + angle_A + " ▁ degree " ) ; Console . WriteLine ( " angle ▁ B ▁ = ▁ " + angle_B + " ▁ degree " ) ; Console . WriteLine ( " angle ▁ C ▁ = ▁ " + angle_C + " ▁ degree " ) ; } }
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
using System ; class GFG { static 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 ; } static void Main ( ) { int N = 12 , M = 13 , s = 4 ; Console . WriteLine ( solve ( M , N , s ) ) ; } }
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
using System ; class GFG { static int solve ( double M , double N , double s ) { int ans = ( ( int ) ( Math . Ceiling ( M / s ) ) * ( int ) ( Math . Ceiling ( N / s ) ) ) ; return ans ; } public static void Main ( ) { double N = 12 , M = 13 , s = 4 ; Console . WriteLine ( solve ( M , N , s ) ) ; } }
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
using System ; class GFG { static 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 ) ; Console . Write ( " equation ▁ of ▁ plane ▁ is ▁ " + a + " x ▁ + ▁ " + b + " y ▁ + ▁ " + c + " z ▁ + ▁ " + d + " ▁ = ▁ 0" ) ; } public static void 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 ) ; } }
Perpendicular distance between a point and a Line in 2 D | C # program to find the distance between a given point and a given line in 2 D . ; Function to find distance ; Driver code
using System ; class GFG { static void shortest_distance ( float x1 , float y1 , float a , float b , float c ) { double d = Math . Abs ( ( ( a * x1 + b * y1 + c ) ) / ( Math . Sqrt ( a * a + b * b ) ) ) ; Console . WriteLine ( " Perpendicular ▁ " + " distance ▁ is ▁ " + d ) ; return ; } public static void Main ( ) { float x1 = 5 ; float y1 = 6 ; float a = - 2 ; float b = 3 ; float c = 4 ; shortest_distance ( x1 , y1 , a , b , c ) ; } }
Program to determine the octant of the axial plane | C # program to print octant of a given point . ; Function to print octant ; Driver Code
using System ; class GFG { static void octant ( float x , float y , float z ) { if ( x >= 0 && y >= 0 && z >= 0 ) Console . WriteLine ( " Point ▁ lies ▁ in ▁ 1st ▁ octant " ) ; else if ( x < 0 && y >= 0 && z >= 0 ) Console . WriteLine ( " Point ▁ lies ▁ in ▁ 2nd ▁ octant " ) ; else if ( x < 0 && y < 0 && z >= 0 ) Console . WriteLine ( " Point ▁ lies ▁ in ▁ 3rd ▁ octant " ) ; else if ( x >= 0 && y < 0 && z >= 0 ) Console . WriteLine ( " Point ▁ lies ▁ in ▁ 4th ▁ octant " ) ; else if ( x >= 0 && y >= 0 && z < 0 ) Console . WriteLine ( " Point ▁ lies ▁ in ▁ 5th ▁ octant " ) ; else if ( x < 0 && y >= 0 && z < 0 ) Console . WriteLine ( " Point ▁ lies ▁ in ▁ 6th ▁ octant " ) ; else if ( x < 0 && y < 0 && z < 0 ) Console . WriteLine ( " Point ▁ lies ▁ in ▁ 7th ▁ octant " ) ; else if ( x >= 0 && y < 0 && z < 0 ) Console . WriteLine ( " Point ▁ lies ▁ in ▁ 8th ▁ octant " ) ; } static public void 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 ) ; } }
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 triangle nC3 = n * ( n - 1 ) * ( n - 2 ) / 6 ; Driver code
using System ; class GFG { static int countNumberOfTriangles ( int n ) { return n * ( n - 1 ) * ( n - 2 ) / 6 ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( countNumberOfTriangles ( n ) ) ; } }
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
using System ; class GFG { static long centeredDodecagonal ( long n ) { return 6 * n * ( n - 1 ) + 1 ; } public static void Main ( String [ ] args ) { long n = 2 ; Console . WriteLine ( centeredDodecagonal ( n ) ) ; n = 9 ; Console . WriteLine ( centeredDodecagonal ( n ) ) ; } }
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 ; Driver Code
using System ; class GFG { static long centeredTridecagonalNum ( long n ) { return ( 13 * n * ( n - 1 ) + 2 ) / 2 ; } public static void Main ( ) { long n = 3 ; Console . WriteLine ( centeredTridecagonalNum ( n ) ) ; n = 10 ; Console . WriteLine ( centeredTridecagonalNum ( n ) ) ; } }
Pentagonal Pyramidal Number | C # 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 Code
using System ; class GFG { static 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 ; } static public void Main ( ) { int n = 4 ; Console . WriteLine ( pentagon_pyramidal ( n ) ) ; } }
Pentagonal Pyramidal Number | C # Program to get nth Pentagonal pyramidal number . ; function to get nth Pentagonal pyramidal number . ; Driver Code
using System ; class GFG { static int pentagon_pyramidal ( int n ) { return n * n * ( n + 1 ) / 2 ; } static public void Main ( ) { int n = 4 ; Console . WriteLine ( pentagon_pyramidal ( n ) ) ; } }
Check if three straight lines are concurrent or not | C # Program to check if three straight line are concurrent or no ; Return true if three line are concurrent , else false . ; Driven Program
using System ; class GFG { static 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 ) ; } public static void Main ( ) { int a1 = 2 , b1 = - 3 , c1 = 5 ; int a2 = 3 , b2 = 4 , c2 = - 7 ; int a3 = 9 , b3 = - 5 , c3 = 8 ; if ( checkConcurrent ( a1 , b1 , c1 , a2 , b2 , c2 , a3 , b3 , c3 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Centered Octadecagonal Number | C # Program to find the nth centered octadecagonal number ; centered octadecagon function ; Formula to calculate nth centered octadecagonal number ; Driver Code
using System ; class GFG { static int center_octadecagon_num ( int n ) { return 9 * n * n - 9 * n + 1 ; } static public void Main ( ) { int n = 3 ; Console . Write ( n + " th ▁ centered ▁ " + " octadecagonal ▁ number ▁ : ▁ " ) ; Console . WriteLine ( center_octadecagon_num ( n ) ) ; n = 13 ; Console . Write ( n + " th ▁ centered ▁ " + " octadecagonal ▁ number ▁ : ▁ " ) ; Console . WriteLine ( center_octadecagon_num ( n ) ) ; } }
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
using System ; class GFG { static int centereddecagonalnum ( int n ) { return ( 5 * n * n + 5 * n + 1 ) ; } static public void Main ( ) { int n = 5 ; Console . Write ( n + " th ▁ centered ▁ decagonal " + " number : ▁ " ) ; Console . WriteLine ( centereddecagonalnum ( n ) ) ; n = 9 ; Console . Write ( n + " th ▁ centered ▁ decagonal " + " number : ▁ " ) ; Console . WriteLine ( centereddecagonalnum ( n ) ) ; } }
Lexicographically Kth smallest way to reach given coordinate from origin | C # Program to find Lexicographically Kth smallest way to reach given coordinate from origin ; Return ( a + b ) ! / a ! b ! ; finding ( a + b ) ! ; finding ( a + b ) ! / a ! ; finding ( a + b ) ! / b ! ; Return the Kth smallest way to reach given coordinate from origin ; if at origin ; if on y - axis ; decrement y . ; Move vertical ; recursive call to take next step . ; If on x - axis ; decrement x . ; Move horizontal . ; recursive call to take next step . ; If x + y C x is greater than K ; Move Horizontal ; recursive call to take next step . ; Move vertical ; recursive call to take next step . ; Driver Code
using System ; class GFG { static int factorial ( int a , int b ) { int res = 1 ; for ( int i = 1 ; i <= ( a + b ) ; i ++ ) res = res * i ; for ( int i = 1 ; i <= a ; i ++ ) res = res / i ; for ( int i = 1 ; i <= b ; i ++ ) res = res / i ; return res ; } static void Ksmallest ( int x , int y , int k ) { if ( x == 0 && y == 0 ) return ; else if ( x == 0 ) { y -- ; Console . Write ( " V " ) ; Ksmallest ( x , y , k ) ; } else if ( y == 0 ) { x -- ; Console . Write ( " H " ) ; Ksmallest ( x , y , k ) ; } else { if ( factorial ( x - 1 , y ) > k ) { Console . Write ( " H " ) ; Ksmallest ( x - 1 , y , k ) ; } else { Console . Write ( " V " ) ; Ksmallest ( x , y - 1 , k - factorial ( x - 1 , y ) ) ; } } } public static void Main ( String [ ] args ) { int x = 2 , y = 2 , k = 2 ; Ksmallest ( x , y , k ) ; } }
Centered pentagonal number | C # Program to find nth Centered pentagonal number ; centered pentagonal number function ; Formula to calculate nth Centered pentagonal number and return it into main function . ; Driver Code
using System ; class GFG { static int centered_pentagonal_Num ( int n ) { return ( 5 * n * n - 5 * n + 2 ) / 2 ; } public static void Main ( ) { int n = 7 ; Console . Write ( n + " th ▁ Centered ▁ " + " pentagonal ▁ number : ▁ " ) ; Console . WriteLine ( centered_pentagonal_Num ( n ) ) ; } }
Find maximum and minimum distance between magnets | C # program for max and min distance ; Function for finding distance between pivots ; Function for minimum distance ; Function for maximum distance ; Driver Code
using System ; class GFG { static int pivotDis ( int x0 , int y0 , int x1 , int y1 ) { return ( int ) Math . Sqrt ( ( x1 - x0 ) * ( x1 - x0 ) + ( y1 - y0 ) * ( y1 - y0 ) ) ; } static int minDis ( int D , int r1 , int r2 ) { return Math . Max ( ( D - r1 - r2 ) , 0 ) ; } static int maxDis ( int D , int r1 , int r2 ) { return D + r1 + r2 ; } public static void Main ( ) { int x0 = 0 , y0 = 0 , x1 = 8 , y1 = 0 , r1 = 4 , r2 = 5 ; int D = pivotDis ( x0 , y0 , x1 , y1 ) ; Console . WriteLine ( " Distance ▁ while ▁ " + " repulsion ▁ = ▁ " + maxDis ( D , r1 , r2 ) ) ; Console . WriteLine ( " Distance ▁ while ▁ " + " attraction ▁ = ▁ " + minDis ( D , r1 , r2 ) ) ; } }
Maximize a value for a semicircle of given radius | C # program to find the maximum value of F ; Function to find the maximum value of F ; using the formula derived for getting the maximum value of F ; Driver code
using System ; class GFG { static double maximumValueOfF ( int R ) { return 4 * R * R + 0.25 ; } public static void Main ( ) { int R = 3 ; Console . WriteLine ( maximumValueOfF ( R ) ) ; } }
Find the other end point of a line with given one end and mid | C # program to find the end point of a line ; function to find the end pointof a line ; find end point for x coordinates ; find end point for y coordinates ; Driver Program
using System ; class GFG { static void otherEndPoint ( int x1 , int y1 , int m1 , int m2 ) { float x2 = ( float ) ( 2 * m1 - x1 ) ; float y2 = ( float ) ( 2 * m2 - y1 ) ; Console . WriteLine ( " x2 ▁ = ▁ " + x2 + " , ▁ " + " y2 ▁ = ▁ " + y2 ) ; } public static void Main ( String [ ] args ) { int x1 = - 4 , y1 = - 1 , m1 = 3 , m2 = 5 ; otherEndPoint ( x1 , y1 , m1 , m2 ) ; } }
Coordinates of rectangle with given points lie inside | Program to find smallest rectangle to conquer all points ; function to print coordinate of smallest rectangle ; find Xmax and Xmin ; find Ymax and Ymin ; print all four coordinates ; Driver code
using System . Linq ; using System ; public class GFG { static void printRect ( int [ ] X , int [ ] Y , int n ) { int Xmax = X . Max ( ) ; int Xmin = X . Min ( ) ; int Ymax = Y . Max ( ) ; int Ymin = Y . Min ( ) ; Console . WriteLine ( " { " + Xmin + " , ▁ " + Ymin + " } " ) ; Console . WriteLine ( " { " + Xmin + " , ▁ " + Ymax + " } " ) ; Console . WriteLine ( " { " + Xmax + " , ▁ " + Ymax + " } " ) ; Console . WriteLine ( " { " + Xmax + " , ▁ " + Ymin + " } " ) ; } static public void Main ( ) { int [ ] X = { 4 , 3 , 6 , 1 , - 1 , 12 } ; int [ ] Y = { 4 , 1 , 10 , 3 , 7 , - 1 } ; int n = X . Length ; printRect ( X , Y , n ) ; } }
Check if a line passes through the origin | C # program to find if line passing through two coordinates also passes through origin or not ; Driver code
using System ; class GFG { static bool checkOrigin ( int x1 , int y1 , int x2 , int y2 ) { return ( x1 * ( y2 - y1 ) == y1 * ( x2 - x1 ) ) ; } public static void Main ( ) { if ( checkOrigin ( 1 , 28 , 2 , 56 ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Number of horizontal or vertical line segments to connect 3 points | C # program to find number of horizontal ( or vertical ) line segments needed to connect three points . ; Function to check if the third point forms a rectangle with other two points at corners ; Returns true if point k can be used as a joining point to connect using two line segments ; Check for the valid polyline with two segments ; Check whether the X - coordinates or Y - cocordinates are same . ; Iterate over all pairs to check for two line segments ; Otherwise answer is three . ; Driver code
using System ; class GFG { static bool isBetween ( int a , int b , int c ) { return ( Math . Min ( a , b ) <= c && c <= Math . Max ( a , b ) ) ; } static bool canJoin ( int [ ] x , int [ ] y , int i , int j , int k ) { return ( x [ k ] == x [ i ] x [ k ] == x [ j ] ) && isBetween ( y [ i ] , y [ j ] , y [ k ] ) || ( y [ k ] == y [ i ] y [ k ] == y [ j ] ) && isBetween ( x [ i ] , x [ j ] , x [ k ] ) ; } static int countLineSegments ( int [ ] x , int [ ] y ) { if ( ( x [ 0 ] == x [ 1 ] && x [ 1 ] == x [ 2 ] ) || ( y [ 0 ] == y [ 1 ] && y [ 1 ] == y [ 2 ] ) ) return 1 ; else if ( canJoin ( x , y , 0 , 1 , 2 ) || canJoin ( x , y , 0 , 2 , 1 ) || canJoin ( x , y , 1 , 2 , 0 ) ) return 2 ; else return 3 ; } public static void Main ( ) { int [ ] x = new int [ 3 ] ; int [ ] y = new int [ 3 ] ; x [ 0 ] = - 1 ; y [ 0 ] = - 1 ; x [ 1 ] = - 1 ; y [ 1 ] = 3 ; x [ 2 ] = 4 ; y [ 2 ] = 3 ; Console . WriteLine ( countLineSegments ( x , y ) ) ; } }
Pythagorean Quadruple | C # code to detect Pythagorean Quadruples . ; function for checking ; Driver function
using System ; class GFG { static Boolean pythagorean_quadruple ( int a , int b , int c , int d ) { int sum = a * a + b * b + c * c ; if ( d * d == sum ) return true ; else return false ; } public static void Main ( ) { int a = 1 , b = 2 , c = 2 , d = 3 ; if ( pythagorean_quadruple ( a , b , c , d ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }