codeparrot/xlcost-text-to-code huggingface dataset:
Length of the Diagonal of the Octagon | C # Program to find the diagonal of the octagon ; Function to find the diagonal of the octagon ; side cannot be negative ; diagonal of the octagon ; Driver code
using System ; class GFG { static double octadiagonal ( double a ) { if ( a < 0 ) return - 1 ; return a * Math . Sqrt ( 4 + ( 2 * Math . Sqrt ( 2 ) ) ) ; } public static void Main ( ) { double a = 4 ; Console . WriteLine ( octadiagonal ( a ) ) ; } }
Program to Calculate the Perimeter of a Decagon | C # program to Calculate the Perimeter of a Decagon ; Function for finding the perimeter ; Driver code
using System ; class GFG { static void CalPeri ( ) { int S = 5 , Perimeter ; Perimeter = 10 * S ; Console . WriteLine ( " The ▁ Perimeter ▁ of ▁ " + " Decagon ▁ is ▁ : ▁ " + Perimeter ) ; } public static void Main ( ) { CalPeri ( ) ; } }
Sum of lengths of all 12 edges of any rectangular parallelepiped | C # program to illustrate the above problem ; function to find the sum of all the edges of parallelepiped ; to calculate the length of one edge ; sum of all the edges of one side ; net sum will be equal to the summation of edges of all the sides ; Driver code ; initialize the area of three faces which has a common vertex
using System ; public class GFG { static double findEdges ( double s1 , double s2 , double s3 ) { double a = Math . Sqrt ( s1 * s2 / s3 ) ; double b = Math . Sqrt ( s3 * s1 / s2 ) ; double c = Math . Sqrt ( s3 * s2 / s1 ) ; double sum = a + b + c ; return 4 * sum ; } static public void Main ( ) { double s1 , s2 , s3 ; s1 = 65 ; s2 = 156 ; s3 = 60 ; Console . WriteLine ( findEdges ( s1 , s2 , s3 ) ) ; } }
Maximum number of pieces in N cuts | C # program to find maximum no of pieces by given number of cuts ; Function for finding maximum pieces with n cuts . ; to maximize number of pieces x is the horizontal cuts ; Now ( x ) is the horizontal cuts and ( n - x ) is vertical cuts , then maximum number of pieces = ( x + 1 ) * ( n - x + 1 ) ; Driver code ; Taking the maximum number of cuts allowed as 3 ; Finding and printing the max number of pieces
using System ; class GFG { public static int findMaximumPieces ( int n ) { int x = n / 2 ; return ( ( x + 1 ) * ( n - x + 1 ) ) ; } static public void Main ( ) { int n = 3 ; Console . Write ( " Max ▁ number ▁ of ▁ pieces ▁ for ▁ n ▁ = ▁ " + n + " ▁ is ▁ " + findMaximumPieces ( 3 ) ) ; } }
Program to check whether 4 points in a 3 | C # program to check if 4 points in a 3 - D plane are Coplanar ; Function to find equation of plane . ; checking if the 4 th point satisfies the above equation ; Driver Code ; function calling
using System ; class GFG { static void equation_plane ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 , int x3 , int y3 , int z3 , int x , int y , int z ) { int a1 = x2 - x1 ; int b1 = y2 - y1 ; int c1 = z2 - z1 ; int a2 = x3 - x1 ; int b2 = y3 - y1 ; int c2 = z3 - z1 ; int a = b1 * c2 - b2 * c1 ; int b = a2 * c1 - a1 * c2 ; int c = a1 * b2 - b1 * a2 ; int d = ( - a * x1 - b * y1 - c * z1 ) ; if ( a * x + b * y + c * z + d == 0 ) Console . WriteLine ( " Coplanar " ) ; else Console . WriteLine ( " Not ▁ Coplanar " ) ; } static public void Main ( ) { int x1 = 3 ; int y1 = 2 ; int z1 = - 5 ; int x2 = - 1 ; int y2 = 4 ; int z2 = - 3 ; int x3 = - 3 ; int y3 = 8 ; int z3 = - 5 ; int x4 = - 3 ; int y4 = 2 ; int z4 = 1 ; equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 , x4 , y4 , z4 ) ; } }
Angle between two Planes in 3D | C # program to find the Angle between two Planes in 3 D . ; Function to find Angle ; Driver code
using System ; class GFG { static void distance ( float a1 , float b1 , float c1 , float a2 , float b2 , float c2 ) { float d = ( a1 * a2 + b1 * b2 + c1 * c2 ) ; float e1 = ( float ) Math . Sqrt ( a1 * a1 + b1 * b1 + c1 * c1 ) ; float e2 = ( float ) Math . Sqrt ( a2 * a2 + b2 * b2 + c2 * c2 ) ; d = d / ( e1 * e2 ) ; float pi = ( float ) 3.14159 ; float A = ( 180 / pi ) * ( float ) ( Math . Acos ( d ) ) ; Console . Write ( " Angle ▁ is ▁ " + A + " ▁ degree " ) ; } public static void Main ( ) { float a1 = 1 ; float b1 = 1 ; float c1 = 2 ; float a2 = 2 ; float b2 = - 1 ; float c2 = 1 ; distance ( a1 , b1 , c1 , a2 , b2 , c2 ) ; } }
Mirror of a point through a 3 D plane | C # program to find Mirror of a point through a 3 D plane ; Function to mirror image ; Driver Code ; function call
using System ; class GFG { static void mirror_point ( int a , int b , int c , int d , int x1 , int y1 , int z1 ) { float k = ( - a * x1 - b * y1 - c * z1 - d ) / ( float ) ( a * a + b * b + c * c ) ; float x2 = a * k + x1 ; float y2 = b * k + y1 ; float z2 = c * k + z1 ; float x3 = 2 * x2 - x1 ; float y3 = 2 * y2 - y1 ; float z3 = 2 * z2 - z1 ; Console . Write ( " x3 ▁ = ▁ " + x3 + " ▁ " ) ; Console . Write ( " y3 ▁ = ▁ " + y3 + " ▁ " ) ; Console . Write ( " z3 ▁ = ▁ " + z3 + " ▁ " ) ; } static public void Main ( ) { int a = 1 ; int b = - 2 ; int c = 0 ; int d = 0 ; int x1 = - 1 ; int y1 = 3 ; int z1 = 4 ; mirror_point ( a , b , c , d , x1 , y1 , z1 ) ; } }
Number of rectangles in a circle of radius R | C # program to find the number of rectangles that can be cut from a circle of Radius R ; Function to return the total possible rectangles that can be cut from the circle ; Diameter = 2 * Radius ; Square of diameter which is the square of the maximum length diagonal ; generate all combinations of a and b in the range ( 1 , ( 2 * Radius - 1 ) ) ( Both inclusive ) ; Calculate the Diagonal length of this rectangle ; If this rectangle 's  Diagonal Length is  less than the Diameter,  it is a valid rectangle,  thus increment counter ; Driver Code ; Radius of the circle
using System ; class GFG { static int countRectangles ( int radius ) { int rectangles = 0 ; int diameter = 2 * radius ; int diameterSquare = diameter * diameter ; for ( int a = 1 ; a < 2 * radius ; a ++ ) { for ( int b = 1 ; b < 2 * radius ; b ++ ) { int diagonalLengthSquare = ( a * a + b * b ) ; if ( diagonalLengthSquare <= diameterSquare ) { rectangles ++ ; } } } return rectangles ; } public static void Main ( ) { int radius = 2 ; int totalRectangles ; totalRectangles = countRectangles ( radius ) ; Console . WriteLine ( totalRectangles + " ▁ rectangles ▁ can ▁ be ▁ " + " cut ▁ from ▁ a ▁ circle ▁ of " + " ▁ Radius ▁ " + radius ) ; } }
Program to check similarity of given two triangles | C # program to check similarity between two triangles . ; Function for AAA similarity ; Check for AAA ; Function for SAS similarity ; angle b / w two smallest sides is largest . ; since we take angle b / w the sides . ; Function for SSS similarity ; Check for SSS ; Driver Code ; function call for AAA similarity ; function call for SSS similarity ; function call for SAS similarity ; Check if triangles are similar or not
using System ; class GFG1 { static int simi_aaa ( int [ ] a1 , int [ ] a2 ) { Array . Sort ( a1 ) ; Array . Sort ( a2 ) ; if ( a1 [ 0 ] == a2 [ 0 ] && a1 [ 1 ] == a2 [ 1 ] && a1 [ 2 ] == a2 [ 2 ] ) return 1 ; else return 0 ; } static int simi_sas ( int [ ] s1 , int [ ] s2 , int [ ] a1 , int [ ] a2 ) { Array . Sort ( a1 ) ; Array . Sort ( a2 ) ; Array . Sort ( s1 ) ; Array . Sort ( s2 ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] ) { if ( a1 [ 2 ] == a2 [ 2 ] ) return 1 ; } if ( s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] ) { if ( a1 [ 0 ] == a2 [ 0 ] ) return 1 ; } if ( s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) { if ( a1 [ 1 ] == a2 [ 1 ] ) return 1 ; } return 0 ; } static int simi_sss ( int [ ] s1 , int [ ] s2 ) { Array . Sort ( s1 ) ; Array . Sort ( s2 ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] && s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] && s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) return 1 ; return 0 ; } public static void Main ( ) { int [ ] s1 = { 2 , 3 , 3 } ; int [ ] s2 = { 4 , 6 , 6 } ; int [ ] a1 = { 80 , 60 , 40 } ; int [ ] a2 = { 40 , 60 , 80 } ; int aaa = simi_aaa ( a1 , a2 ) ; int sss = simi_sss ( s1 , s2 ) ; int sas = simi_sas ( s1 , s2 , a1 , a2 ) ; if ( aaa == 1 sss == 1 sas == 1 ) { Console . Write ( " Triangles ▁ are ▁ " + " similar ▁ by ▁ " ) ; if ( aaa == 1 ) Console . Write ( " AAA ▁ " ) ; if ( sss == 1 ) Console . Write ( " SSS ▁ " ) ; if ( sas == 1 ) Console . Write ( " SAS . " ) ; } else Console . WriteLine ( " Triangles ▁ are ▁ " + " not ▁ similar " ) ; } }
Centered Pentadecagonal Number | C # Program to find nth centered pentadecagonal number ; centered pentadecagonal function ; Formula to calculate nth centered pentadecagonal number ; Driver Code
using System ; class GFG { static long center_pentadecagonal_num ( long n ) { return ( 15 * n * n - 15 * n + 2 ) / 2 ; } static public void Main ( ) { long n = 3 ; Console . Write ( n + " th ▁ number ▁ : ▁ " ) ; Console . WriteLine ( center_pentadecagonal_num ( n ) ) ; n = 10 ; Console . Write ( n + " th ▁ number ▁ : ▁ " ) ; Console . WriteLine ( center_pentadecagonal_num ( n ) ) ; } }
Centered nonadecagonal number | C # Program to find nth centered nonadecagonal number ; centered nonadecagonal function ; Formula to calculate nth centered nonadecagonal number ; Driver code
using System ; class GFG { static int center_nonadecagon_num ( int n ) { return ( 19 * n * n - 19 * n + 2 ) / 2 ; } static public void Main ( ) { int n = 2 ; Console . Write ( n + " th ▁ centered ▁ " + " nonadecagonal ▁ number ▁ : ▁ " ) ; Console . WriteLine ( center_nonadecagon_num ( n ) ) ; n = 7 ; Console . Write ( n + " th ▁ centered ▁ " + " nonadecagonal ▁ number ▁ : ▁ " ) ; Console . WriteLine ( center_nonadecagon_num ( n ) ) ; } }
Hendecagonal number | C # program to find nth Hendecagonal number ; Function to find Hendecagonal number ; Formula to calculate nth Hendecagonal number ; Driver Code
using System ; class GFG { static int hendecagonal_num ( int n ) { return ( 9 * n * n - 7 * n ) / 2 ; } static public void Main ( ) { int n = 3 ; Console . Write ( n + " rd ▁ Hendecagonal ▁ number : ▁ " ) ; Console . WriteLine ( hendecagonal_num ( n ) ) ; n = 10 ; Console . Write ( n + " th ▁ Hendecagonal ▁ number : ▁ " ) ; Console . WriteLine ( hendecagonal_num ( n ) ) ; } }
Centered Octagonal Number | Program to find nth centered octagonal number ; Centered octagonal number function ; Formula to calculate nth centered octagonal number & return it into main function . ; Driver code
using System ; public class GFG { static long cen_octagonalnum ( long n ) { return ( 4 * n * n - 4 * n + 1 ) ; } static public void Main ( ) { long n = 6 ; Console . WriteLine ( n + " th ▁ centered " + " ▁ octagonal ▁ number ▁ : ▁ " + cen_octagonalnum ( n ) ) ; n = 11 ; Console . WriteLine ( n + " th ▁ centered " + " ▁ octagonal ▁ number ▁ : ▁ " + cen_octagonalnum ( n ) ) ; } }
Number of ordered points pair satisfying line equation | C # code to find number of ordered points satisfying line equation ; Checks if ( i , j ) is valid , a point ( i , j ) is valid if point ( arr [ i ] , arr [ j ] ) satisfies the equation y = mx + c And i is not equal to j ; check if i equals to j ; Equation LHS = y , and RHS = mx + c ; Returns the number of ordered pairs ( i , j ) for which point ( arr [ i ] , arr [ j ] ) satisfies the equation of the line y = mx + c ; for every possible ( i , j ) check if ( a [ i ] , a [ j ] ) satisfies the equation y = mx + c ; ( firstIndex , secondIndex ) is same as ( i , j ) ; check if ( firstIndex , secondIndex ) is a valid point ; Driver Code ; equation of line is y = mx + c
using System ; class GFG { static bool isValid ( int [ ] arr , int i , int j , int m , int c ) { if ( i == j ) return false ; int lhs = arr [ j ] ; int rhs = m * arr [ i ] + c ; return ( lhs == rhs ) ; } static int findOrderedPoints ( int [ ] arr , int n , int m , int c ) { int counter = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { int firstIndex = i , secondIndex = j ; if ( isValid ( arr , firstIndex , secondIndex , m , c ) ) counter ++ ; } } return counter ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 2 } ; int n = arr . Length ; int m = 1 , c = 1 ; Console . Write ( findOrderedPoints ( arr , n , m , c ) ) ; } }
Check if a given circle lies completely inside the ring formed by two concentric circles | C # code to check if a circle lies in the ring ; Function to check if circle lies in the ring ; distance between center of circle center of concentric circles ( origin ) using Pythagoras theorem ; Condition to check if circle is strictly inside the ring ; Driver Code ; Both circle with radius ' r ' and ' R ' have center ( 0 , 0 )
using System ; class ring { public static bool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) { int dis = ( int ) Math . Sqrt ( x1 * x1 + y1 * y1 ) ; return ( dis - r1 >= R && dis + r1 <= r ) ; } public static void Main ( ) { int r = 8 , R = 4 , r1 = 2 , x1 = 6 , y1 = 0 ; if ( checkcircle ( r , R , r1 , x1 , y1 ) ) Console . WriteLine ( " yes " ) ; else Console . WriteLine ( " no " ) ; } }
Program for Surface Area of Octahedron | C # program to calculate surface area of Octahedron . ; utility Function ; Driver code
using System ; class GFG { static double surface_area_octahedron ( double side ) { return ( 2 * ( Math . Sqrt ( 3 ) ) * ( side * side ) ) ; } public static void Main ( ) { double side = 7 ; Console . WriteLine ( " Surface ▁ area ▁ of ▁ octahedron ▁ = " + surface_area_octahedron ( side ) ) ; } }
Count of different straight lines with total n points with m collinear | C # program to count number of straight lines with n total points , out of which m are collinear . ; Returns value of binomial coefficient Code taken from https : goo . gl / vhy4jp ; nC0 is 1 ; Compute next row of pascal triangle using the previous row ; Function to calculate number of straight lines can be formed ; Driver Code
using System ; public class GfG { public static int nCk ( int n , int k ) { int [ ] C = new int [ k + 1 ] ; C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . Min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } public static int count_Straightlines ( int n , int m ) { return ( nCk ( n , 2 ) - nCk ( m , 2 ) + 1 ) ; } public static void Main ( String [ ] args ) { int n = 4 , m = 3 ; Console . WriteLine ( count_Straightlines ( n , m ) ) ; } }
Calculate Volume of Dodecahedron | C # program to calculate Volume of dodecahedron ; utility Function ; Driver Function
using System ; public class GFG { static float vol_of_dodecahedron ( int side ) { return ( float ) ( ( ( 15 + ( 7 * ( Math . Sqrt ( 5 ) ) ) ) / 4 ) * ( Math . Pow ( side , 3 ) ) ) ; } static public void Main ( ) { int side = 4 ; Console . WriteLine ( " Volume ▁ of ▁ dodecahedron ▁ = ▁ " + vol_of_dodecahedron ( side ) ) ; } }
Program to check if water tank overflows when n solid balls are dipped in the water tank | C # Code for Program to check if water tank overflows ; function to find if tak will overflow or not ; cylinder capacity ; volume of water in tank ; volume of n balls ; total volume of water and n dipped balls ; condition to check if tank is in overflow state or not ; Driver program to test above function ; giving dimensions ; calling function
using System ; class GFG { static void overflow ( int H , int r , int h , int N , int R ) { double tank_cap = 3.14 * r * r * H ; double water_vol = 3.14 * r * r * h ; double balls_vol = N * ( 4 / 3 ) * 3.14 * R * R * R ; double vol = water_vol + balls_vol ; if ( vol > tank_cap ) { Console . WriteLine ( " Overflow " ) ; } else { Console . WriteLine ( " Not ▁ in ▁ overflow ▁ state " ) ; } } public static void Main ( ) { int H = 10 , r = 5 , h = 5 , N = 2 , R = 2 ; overflow ( H , r , h , N , R ) ; } }
Program to check if tank will overflow , underflow or filled in given time | C # program to check if Tank will overflow or not in given time ; function to calculate the volume of tank ; function to print overflow / filled / underflow accordingly ; driver code ; radius of the tank ; height of the tank ; rate of flow of water ; time given ; calculate the required time ; printing the result
using System ; class Number { public static float volume ( int radius , int height ) { return ( ( 22 / 7 ) * radius * radius * height ) ; } public static void check_and_print ( double required_time , double given_time ) { if ( required_time < given_time ) Console . WriteLine ( " Overflow " ) ; else if ( required_time > given_time ) Console . WriteLine ( " Underflow " ) ; else Console . WriteLine ( " Filled " ) ; } public static void Main ( ) { int radius = 5 , height = 10 , rate_of_flow = 10 ; double given_time = 70.0 ; double required_time = volume ( radius , height ) / rate_of_flow ; check_and_print ( required_time , given_time ) ; } }
Program to find third side of triangle using law of cosines | C # program to find third side of triangle using law of cosines ; Function to calculate cos value of angle c ; Converting degrees to radian ; Maps the sum along the series ; Holds the actual value of sin ( n ) ; Function to find third side ; Driver code ; function call
using System ; class GFG { static float cal_cos ( float n ) { float accuracy = 0.0001f , x1 ; float denominator , cosx , cosval ; n = n * ( 3.142f / 180.0f ) ; x1 = 1 ; cosx = x1 ; cosval = ( float ) Math . Cos ( n ) ; int i = 1 ; do { denominator = 2 * i * ( 2 * i - 1 ) ; x1 = - x1 * n * n / denominator ; cosx = cosx + x1 ; i = i + 1 ; } while ( accuracy <= Math . Abs ( cosval - cosx ) ) ; return cosx ; } static float third_side ( int a , int b , float c ) { float angle = cal_cos ( c ) ; return ( float ) Math . Sqrt ( ( a * a ) + ( b * b ) - 2 * a * b * angle ) ; } public static void Main ( ) { float c = 49 ; int a = 5 , b = 8 ; Console . WriteLine ( Math . Round ( third_side ( a , b , c ) * 100000.0 ) / 100000.0 ) ; } }
Check whether given circle resides in boundary maintained by two other circles | C # program to check whether circle with given co - ordinates reside within the boundary of outer circle and inner circle ; function to check if given circle fit in boundary or not ; Distance from the center ; Checking the corners of circle ; Driver program ; Radius of outer circle and inner circle respectively ; Co - ordinates and radius of the circle to be checked
using System ; class GFG { static void fitOrNotFit ( int R , int r , int x , int y , int rad ) { double val = Math . Sqrt ( Math . Pow ( x , 2 ) + Math . Pow ( y , 2 ) ) ; if ( val + rad <= R && val - rad >= R - r ) Console . WriteLine ( " Fits " ) ; else Console . WriteLine ( " Doesn ' t ▁ Fit " ) ; } public static void Main ( ) { int R = 8 , r = 4 ; int x = 5 , y = 3 , rad = 3 ; fitOrNotFit ( R , r , x , y , rad ) ; } }
Number of Triangles that can be formed given a set of lines in Euclidean Plane | C # program to find the number of triangles that can be formed using a set of lines in Euclidean Plane ; Double variables can ' t ▁ be ▁ checked ▁ precisely ▁ using ▁ ' == ' this function returns true if the double variables are equal ; This function returns the number of triangles for a given set of lines ; Slope array stores the slope of lines ; Slope array is sorted so that all lines with same slope come together ; After sorting slopes , count different slopes . k is index in count [ ] . ; Count of current slope ; Calculating sum1 ( Sum of all slopes ) sum1 = m1 + m2 + ... ; Calculating sum2 . sum2 = m1 * m2 + m2 * m3 + ... ; Needed for sum3 ; Calculating sum3 which gives the final answer m1 * m2 * m3 + m2 * m3 * m4 + ... ; Driver code ; lines are stored as arrays of a , b and c for ' ax + by = c ' ; n is the number of lines
using System . Collections . Generic ; using System ; class GFG { static double EPSILON = 1.0842e-19 ; static bool compareDoubles ( double A , double B ) { double diff = A - B ; return ( diff < EPSILON ) && ( - diff < EPSILON ) ; } static int numberOfTringles ( int [ ] a , int [ ] b , int [ ] c , int n ) { List < double > slope = new List < double > ( ) ; for ( int i = 0 ; i < n ; i ++ ) slope . Add ( ( double ) ( a [ i ] * 1.0 ) / b [ i ] ) ; slope . Sort ( ) ; int [ ] count = new int [ n ] ; int k = 0 ; int this_count = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( compareDoubles ( ( double ) slope [ i ] , ( double ) slope [ i - 1 ] ) ) this_count ++ ; else { count [ k ++ ] = this_count ; this_count = 1 ; } } count [ k ++ ] = this_count ; int sum1 = 0 ; for ( int i = 0 ; i < k ; i ++ ) sum1 += count [ i ] ; int sum2 = 0 ; int [ ] temp = new int [ n ] ; for ( int i = 0 ; i < k ; i ++ ) { temp [ i ] = count [ i ] * ( sum1 - count [ i ] ) ; sum2 += temp [ i ] ; } sum2 /= 2 ; int sum3 = 0 ; for ( int i = 0 ; i < k ; i ++ ) sum3 += count [ i ] * ( sum2 - temp [ i ] ) ; sum3 /= 3 ; return sum3 ; } public static void Main ( ) { int [ ] a = { 1 , 2 , 3 , 4 } ; int [ ] b = { 2 , 4 , 5 , 5 } ; int [ ] c = { 5 , 7 , 8 , 6 } ; int n = a . Length ; Console . WriteLine ( " The ▁ number ▁ of ▁ triangles ▁ " + " that ▁ can ▁ be ▁ formed ▁ are : ▁ " + numberOfTringles ( a , b , c , n ) ) ; } }
Program to find line passing through 2 Points | C # Implementation to find the line passing through two points ; This pair is used to store the X and Y coordinate of a point respectively ; Function to find the line given two points ; Driver code
using System ; class GFG { public class Pair { public int first , second ; public Pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void lineFromPoints ( Pair P , Pair Q ) { int a = Q . second - P . second ; int b = P . first - Q . first ; int c = a * ( P . first ) + b * ( P . second ) ; if ( b < 0 ) { Console . WriteLine ( " The ▁ line ▁ passing ▁ through ▁ points ▁ P ▁ and ▁ Q ▁ is : ▁ " + a + " x ▁ - ▁ " + b + " y ▁ = ▁ " + c ) ; } else { Console . WriteLine ( " The ▁ line ▁ passing ▁ through ▁ points ▁ P ▁ and ▁ Q ▁ is : ▁ " + a + " x ▁ + ▁ " + b + " y ▁ = ▁ " + c ) ; } } public static void Main ( String [ ] args ) { Pair P = new Pair ( 3 , 2 ) ; Pair Q = new Pair ( 2 , 6 ) ; lineFromPoints ( P , Q ) ; } }
Regular polygon using only 1 s in a binary numbered circle | C # program to find whether a regular polygon is possible in circle with 1 s as vertices ; method returns true if polygon is possible with ' midpoints ' number of midpoints ; loop for getting first vertex of polygon ; loop over array values at ' midpoints ' distance ; and ( & ) all those values , if even one of them is 0 , val will be 0 ; if val is still 1 and ( N / midpoints ) or ( number of vertices ) are more than two ( for a polygon minimum ) print result and return true ; method prints sides in the polygon or print not possible in case of no possible polygon ; limit for iterating over divisors ; If i divides N then i and ( N / i ) will be divisors ; check polygon for both divisors ; Driver Code
using System ; class GFG { static bool checkPolygonWithMidpoints ( int [ ] arr , int N , int midpoints ) { for ( int j = 0 ; j < midpoints ; j ++ ) { int val = 1 ; for ( int k = j ; k < N ; k += midpoints ) { val &= arr [ k ] ; } if ( val != 0 && N / midpoints > 2 ) { Console . WriteLine ( " Polygon ▁ possible ▁ with ▁ " + " side ▁ length ▁ " + N / midpoints ) ; return true ; } } return false ; } static void isPolygonPossible ( int [ ] arr , int N ) { int limit = ( int ) Math . Sqrt ( N ) ; for ( int i = 1 ; i <= limit ; i ++ ) { if ( N % i == 0 ) { if ( checkPolygonWithMidpoints ( arr , N , i ) || checkPolygonWithMidpoints ( arr , N , ( N / i ) ) ) return ; } } Console . WriteLine ( " Not ▁ possible " ) ; } static public void Main ( ) { int [ ] arr = { 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 } ; isPolygonPossible ( arr , arr . Length ) ; } }
Maximum height when coins are arranged in a triangle | C # program to find maximum height of arranged coin triangle ; Returns the square root of n . Note that the function ; We are using n itself as initial approximation . This can definitely be improved ; e decides the accuracy level ; Method to find maximum height of arrangement of coins ; calculating portion inside the square root ; program to test above function
using System ; class GFG { static float squareRoot ( float n ) { float x = n ; float y = 1 ; float e = 0.000001f ; while ( x - y > e ) { x = ( x + y ) / 2 ; y = n / x ; } return x ; } static int findMaximumHeight ( int N ) { int n = 1 + 8 * N ; int maxH = ( int ) ( - 1 + squareRoot ( n ) ) / 2 ; return maxH ; } public static void Main ( ) { int N = 12 ; Console . Write ( findMaximumHeight ( N ) ) ; } }