codeparrot/xlcost-text-to-code huggingface dataset:
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 ; 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
using System ; using System . Collections . Generic ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static List < pair > FindPoints ( int n ) { List < pair > v = new List < pair > ( ) ; v . Add ( new pair ( 0 , 0 ) ) ; v . Add ( new pair ( 0 , n ) ) ; v . Add ( new pair ( n , 0 ) ) ; v . Add ( new pair ( n , n ) ) ; if ( n % 2 == 0 ) v . Add ( new pair ( n / 2 , n / 2 ) ) ; return v ; } public static void Main ( String [ ] args ) { int N = 8 ; List < pair > v = FindPoints ( N ) ; foreach ( pair i in v ) { Console . Write ( " ( " + i . first + " , ▁ " + i . second + " ) ▁ " ) ; } } }
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
using System ; class GFG { static double pie = 3.1415926535897 ; static 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 ; } public static void Main ( String [ ] args ) { double d = 1 , h = 1 , m = 1 , n = 1 ; Console . Write ( " { 0 : F5 } " , findsolution ( d , h , m , n ) ) ; } }
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
using System ; class GFG { static int sumOfInternalAngles ( int n ) { if ( n < 3 ) return 0 ; return ( ( n - 2 ) * 180 ) ; } public static void Main ( ) { int n = 5 ; Console . Write ( sumOfInternalAngles ( n ) ) ; } }
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
using System ; class GFG { static int cntWays ( int n ) { if ( n % 2 == 1 ) { return 0 ; } else { return ( n - 2 ) / 4 ; } } public static void Main ( String [ ] args ) { int n = 18 ; Console . WriteLine ( cntWays ( n ) ) ; } }
Forming triangles using points on a square | C # implementation of the above approach ; Function to return the count of possible triangles ; Driver code
using System ; class GFG { static int noOfTriangles ( int n ) { int y = 4 * n ; return ( ( y * ( y - 2 ) * ( y - 1 ) ) - ( 4 * n * ( n - 2 ) * ( n - 1 ) ) ) / 6 ; } public static void Main ( String [ ] args ) { int n = 1 ; Console . WriteLine ( noOfTriangles ( n ) ) ; } }
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
using System ; class GFG { static int angle ( int n ) { return 2 * n ; } public static void Main ( ) { int n = 30 ; Console . Write ( angle ( n ) ) ; } }
Check if two given Circles are Orthogonal or not | C # implementation for above program ; 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
using System ; class GFG { public static 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 ; } public static void 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 ) Console . WriteLine ( " Given ▁ circles ▁ are ▁ orthogonal . " ) ; else Console . WriteLine ( " Given ▁ circles ▁ are ▁ not ▁ orthogonal . " ) ; } }
Check if a right | C # implementation of the 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
using System ; class GFG { static int [ ] dx = { - 1 , 0 , 1 , 0 } ; static int [ ] dy = { 0 , 1 , 0 , - 1 } ; static bool 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 true ; } return false ; } static void isValidCombination ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { int x , y ; bool possible = false ; if ( ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) ) { Console . WriteLine ( " 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 ) ) { Console . WriteLine ( " POSSIBLE " ) ; return ; } x = dx [ i ] + x2 ; y = dy [ i ] + y2 ; if ( ifRight ( x1 , y1 , x , y , x3 , y3 ) ) { Console . WriteLine ( " POSSIBLE " ) ; return ; } x = dx [ i ] + x3 ; y = dy [ i ] + y3 ; if ( ifRight ( x1 , y1 , x2 , y2 , x , y ) ) { Console . Write ( " POSSIBLE " ) ; return ; } } } if ( ! possible ) Console . WriteLine ( " NOT ▁ POSSIBLE " ) ; } static public void Main ( ) { int x1 = - 49 , y1 = 0 ; int x2 = 0 , y2 = 50 ; int x3 = 0 , y3 = - 50 ; isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 ) ; } }
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
using System ; class GFG { static double area_of_regular_polygon ( double n , double len ) { double P = ( len * n ) ; double A = len / ( 2 * Math . Tan ( ( 180 / n ) * 3.14159 / 180 ) ) ; double area = ( P * A ) / 2 ; return area ; } static 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 ; } static public void Main ( String [ ] arg ) { double n = 6 , len = 10 ; Console . Write ( " { 0 : F3 } " , area_of_triangle_inscribed ( n , len ) ) ; } }
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
using System ; class GFG { static float Area ( int d , int h1 , int h2 ) { float area ; area = ( float ) 0.5 * d * ( h1 + h2 ) ; return area ; } public static void Main ( ) { int d = 6 , h1 = 4 , h2 = 3 ; Console . WriteLine ( " Area ▁ of ▁ Quadrilateral ▁ = ▁ " + Area ( d , h1 , h2 ) ) ; } }
Find the diagonal of the Cube | C # 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
using System ; class GFG { static float diagonal_length ( float a ) { float L ; L = a * ( float ) Math . Sqrt ( 3 ) ; return L ; } public static void Main ( ) { float a = 5 ; Console . Write ( diagonal_length ( a ) ) ; } }
Concentric Hexagonal Numbers | C # program to find nth concentric hexagon number ; Function to find nth concentric hexagon number ; Driver code ; Function call
using System ; class GFG { static int concentric_Hexagon ( int n ) { return 3 * ( int ) Math . Pow ( n , 2 ) / 2 ; } public static void Main ( ) { int n = 3 ; Console . WriteLine ( concentric_Hexagon ( n ) ) ; } }
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
using System ; public class GFG { static double PI = 3.14 ; static double find_area ( int r , int d ) { double R = d / PI ; R += Math . Pow ( r , 2 ) ; R = Math . Sqrt ( R ) ; double area = PI * Math . Pow ( R , 2 ) ; return area ; } static public void Main ( ) { int r = 4 , d = 5 ; Console . Write ( find_area ( r , d ) ) ; } }
Check whether Quadrilateral is valid or not if angles are given | C # program to check if a given quadrilateral is valid or not ; Function to check if a given quadrilateral is valid or not ; Check condition ; Driver code
class GFG { static bool Valid ( int a , int b , int c , int d ) { if ( a + b + c + d == 360 ) return true ; return false ; } public static void Main ( ) { int a = 80 , b = 70 , c = 100 , d = 110 ; if ( Valid ( a , b , c , d ) ) Console . WriteLine ( " Valid ▁ quadrilateral " ) ; else Console . WriteLine ( " Invalid ▁ quadrilateral " ) ; } }
Central angle of a N sided Regular Polygon | C # program for the above approach ; Function to calculate central angle of a polygon ; Calculate the angle ; Driver code
using System ; class GFG { static double calculate_angle ( double n ) { double total_angle = 360 ; return total_angle / n ; } public static void Main ( ) { double N = 5 ; Console . WriteLine ( calculate_angle ( N ) ) ; } }
Program to calculate the area of Kite | C # implementation of the approach ; Function to return the area of kite ; Use above formula ; Driver code
using System ; class GFG { static float areaOfKite ( int d1 , int d2 ) { float area = ( d1 * d2 ) / 2 ; return area ; } public static void Main ( ) { int d1 = 4 , d2 = 6 ; Console . WriteLine ( " Area ▁ of ▁ Kite ▁ = ▁ " + areaOfKite ( d1 , d2 ) ) ; } }
Program to calculate the area of Kite | C # implementation of the approach ; Function to return the area of the kite ; convert angle degree to radians ; use above formula ; Driver code
using System ; class GFG { static double PI = ( 3.14159 / 180 ) ; static float areaOfKite ( int a , int b , double angle ) { angle = angle * PI ; double area = a * b * Math . Sin ( angle ) ; return ( float ) area ; } static public void Main ( ) { int a = 4 , b = 7 , angle = 78 ; Console . WriteLine ( " Area ▁ of ▁ Kite ▁ = ▁ " + areaOfKite ( a , b , angle ) ) ; } }
Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given | C # Program to calculate angle on the circumference subtended by the chord when the central angle subtended by the chord is given ; Driver code ; Angle on center
using System ; public class GFG { static float angleOncirCumference ( float z ) { return ( z / 2 ) ; } public static void Main ( String [ ] args ) { float angle = 65 ; float z = angleOncirCumference ( angle ) ; Console . WriteLine ( " The ▁ angle ▁ is ▁ " + z + " ▁ degrees " ) ; } }
Maximum and Minimum value of a quadratic function | C # implementation of the above approach ; Function to print the Maximum and Minimum values of the quadratic function ; Calculate the value of second part ; Print the values ; Open upward parabola function ; Open downward parabola function ; If a = 0 then it is not a quadratic function ; Driver code
using System ; class GFG { static void PrintMaxMinValue ( double a , double b , double c ) { double secondPart = c * 1.0 - ( b * b / ( 4.0 * a ) ) ; if ( a > 0 ) { Console . Write ( " Maxvalue ▁ = ▁ " + " Infinity STRNEWLINE " ) ; Console . Write ( " Minvalue ▁ = ▁ " + secondPart ) ; } else if ( a < 0 ) { Console . Write ( " Maxvalue ▁ = ▁ " + secondPart + " STRNEWLINE " ) ; Console . Write ( " Minvalue ▁ = ▁ " + " - Infinity " ) ; } else { Console . Write ( " Not ▁ a ▁ quadratic ▁ function STRNEWLINE " ) ; } } static public void Main ( ) { double a = - 1 , b = 3 , c = - 2 ; PrintMaxMinValue ( a , b , c ) ; } }
Percentage increase in the cylinder if the height is increased by given percentage but radius remains constant | C # program to find percentage increase in the cylinder if the height is increased by given percentage but radius remains constant ; Driver code
using System ; class GFG { static void newvol ( double x ) { Console . WriteLine ( " percentage ▁ increase ▁ " + " in ▁ the ▁ volume ▁ of ▁ the ▁ cylinder ▁ is ▁ " + x + " % " ) ; } public static void Main ( ) { double x = 10 ; newvol ( x ) ; } }
Find the side of the squares which are inclined diagonally and lined in a row | C # program to find side of the squares inclined and touch each other externally at vertices and are lined in a row and distance between the centers of first and last squares is given ; Driver code
using System ; class GFG { static void radius ( double n , double d ) { Console . WriteLine ( " The ▁ side ▁ of ▁ each ▁ square ▁ is ▁ " + d / ( ( n - 1 ) * Math . Sqrt ( 2 ) ) ) ; } public static void Main ( ) { double d = 42 , n = 4 ; radius ( n , d ) ; } }
Program to calculate area of inner circle which passes through center of outer circle and touches its circumference | C # Implementation of the above approach ; Function calculate the area of the inner circle ; the radius cannot be negative ; area of the circle ; Driver Code
using System ; class GFG { static double innerCirclearea ( double radius ) { if ( radius < 0 ) { return - 1 ; } double r = radius / 2 ; double Area = ( 3.14 * Math . Pow ( r , 2 ) ) ; return Area ; } public static void Main ( String [ ] arr ) { double radius = 4 ; Console . WriteLine ( " Area ▁ of ▁ circle ▁ c2 ▁ = ▁ " + innerCirclearea ( radius ) ) ; } }
Angle subtended by the chord when the angle subtended by another chord of same length is given | C # program to find the angle subtended at the center by the chord when the angle subtended at center by another chord of equal length is given ; Driver code
using System ; class GFG { static void angleequichord ( int z ) { Console . WriteLine ( " The ▁ angle ▁ subtended ▁ at ▁ the ▁ center ▁ is ▁ " + z + " ▁ degrees " ) ; } public static void Main ( String [ ] args ) { int z = 48 ; angleequichord ( z ) ; } }
Distance of chord from center when distance between center and another equal length chord is given | C # program to find the distance of chord from center when distance between center and another equal length chord is given ; Driver code
using System ; class GFG { static void lengequichord ( int z ) { Console . WriteLine ( " The ▁ distance ▁ between ▁ the ▁ " + " chord ▁ and ▁ the ▁ center ▁ is ▁ " + z ) ; } public static void Main ( ) { int z = 48 ; lengequichord ( z ) ; } }
Length of the perpendicular bisector of the line joining the centers of two circles | C # program to find the Length of the perpendicular bisector of the line joining the centers of two circles in which one lies completely inside touching the bigger circle at one point ; Driver code
using System ; class GFG { static void lengperpbisect ( double r1 , double r2 ) { double z = 2 * Math . Sqrt ( ( r1 * r1 ) - ( ( r1 - r2 ) * ( r1 - r2 ) / 4 ) ) ; Console . WriteLine ( " The ▁ length ▁ of ▁ the ▁ " + " perpendicular ▁ bisector ▁ is ▁ " + z ) ; } public static void Main ( ) { double r1 = 5 , r2 = 3 ; lengperpbisect ( r1 , r2 ) ; } }
Length of the chord the circle if length of the another chord which is equally inclined through the diameter is given | C # program to find the length of the chord the circle if length of the another chord which is equally inclined through the diameter is given ; Driver code
using System ; class GFG { static void lengchord ( int z ) { Console . WriteLine ( " The ▁ length ▁ is ▁ " + z ) ; } static public void Main ( ) { int z = 48 ; lengchord ( z ) ; } }
Distance between centers of two intersecting circles if the radii and common chord length is given | C # program to find the distance between centers of two intersecting circles if the radii and common chord length is given ; Driver code
using System ; class GFG { static double distcenter ( int r1 , int r2 , int x ) { double z = ( Math . Sqrt ( ( r1 * r1 ) - ( x / 2 * x / 2 ) ) ) + ( Math . Sqrt ( ( r2 * r2 ) - ( x / 2 * x / 2 ) ) ) ; Console . WriteLine ( " distance ▁ between ▁ the " + " ▁ centers ▁ is ▁ " + ( int ) z ) ; return 0 ; } static public void Main ( ) { int r1 = 24 , r2 = 37 , x = 40 ; distcenter ( r1 , r2 , x ) ; } }
Exterior angle of a cyclic quadrilateral when the opposite interior angle is given | C # program to find the exterior angle of a cyclic quadrilateral when the opposite interior angle is given ; Driver code
using System ; class GFG { static void angleextcycquad ( int z ) { Console . WriteLine ( " The ▁ exterior ▁ angle ▁ of ▁ the " + " ▁ cyclic ▁ quadrilateral ▁ is ▁ " + z + " ▁ degrees " ) ; } public static void Main ( ) { int z = 48 ; angleextcycquad ( z ) ; } }
Angle between a chord and a tangent when angle in the alternate segment is given | C # program to find the angle between a chord and a tangent when angle in the alternate segment is given ; Driver code
using System ; class GFG { static void anglechordtang ( int z ) { Console . WriteLine ( " The ▁ angle ▁ between ▁ tangent " + " ▁ and ▁ the ▁ chord ▁ is ▁ " + z + " ▁ degrees " ) ; } public static void Main ( ) { int z = 48 ; anglechordtang ( z ) ; } }
Print all Perfect Numbers from an array whose sum of digits is also a Perfect Number | C # program for the above approach ; Function to check if a number is perfect number or not ; Stores sum of proper divisors ; If sum of digits is equal to N , then it 's a perfect number ; Otherwise , not a perfect number ; Function to find the sum of digits of a number ; Stores sum of digits ; Return sum of digits ; Function to count perfect numbers from an array whose sum of digits is also perfect ; Traverse the array ; If number is perfect ; Stores sum of digits of the number ; If that is also perfect number ; Print that number ; Driver Code ; Given array ; Size of the array ; Function call to count perfect numbers having sum of digits also perfect
using System ; class GFG { static bool isPerfect ( int N ) { int sumOfDivisors = 1 ; for ( int i = 2 ; i <= N / 2 ; ++ i ) { if ( N % i == 0 ) { sumOfDivisors += i ; } } if ( sumOfDivisors == N ) { return true ; } else return false ; } static int sumOfDigits ( int N ) { int sum = 0 ; while ( N != 0 ) { sum += ( N % 10 ) ; N = N / 10 ; } return sum ; } static void countPerfectNumbers ( int [ ] arr , int N ) { for ( int i = 0 ; i < N ; ++ i ) { if ( isPerfect ( arr [ i ] ) ) { int sum = sumOfDigits ( arr [ i ] ) ; if ( isPerfect ( sum ) ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } } } static public void Main ( ) { int [ ] arr = { 3 , 8 , 12 , 28 , 6 } ; int N = arr . Length ; countPerfectNumbers ( arr , N ) ; } }
Maximum Prefix Sum possible by merging two given arrays | C # implementation of above approach ; Stores the dp states ; Recursive Function to calculate the maximum prefix sum ontained by merging two arrays ; If subproblem is already computed ; If x >= N or y >= M ; If x < N ; If y < M ; Otherwise ; Driver code
using System ; using System . Collections . Generic ; class GFG { static Dictionary < Tuple < int , int > , int > dp = new Dictionary < Tuple < int , int > , int > ( ) ; static int maxPreSum ( int [ ] a , int [ ] b , int x , int y ) { if ( dp . ContainsKey ( new Tuple < int , int > ( x , y ) ) ) return dp [ new Tuple < int , int > ( x , y ) ] ; if ( x == a . Length && y == b . Length ) return 0 ; int curr = 0 ; if ( dp . ContainsKey ( new Tuple < int , int > ( x , y ) ) ) { curr = dp [ new Tuple < int , int > ( x , y ) ] ; } if ( x == a . Length ) { curr = Math . Max ( curr , b [ y ] + maxPreSum ( a , b , x , y + 1 ) ) ; } else if ( y == b . Length ) { curr = Math . Max ( curr , a [ x ] + maxPreSum ( a , b , x + 1 , y ) ) ; } else { int max = Math . Max ( a [ x ] + maxPreSum ( a , b , x + 1 , y ) , b [ y ] + maxPreSum ( a , b , x , y + 1 ) ) ; curr = Math . Max ( curr , max ) ; } dp [ new Tuple < int , int > ( x , y ) ] = curr ; return dp [ new Tuple < int , int > ( x , y ) ] ; } static void Main ( ) { int [ ] A = { 2 , 1 , 13 , 5 , 14 } ; int [ ] B = { - 1 , 4 , - 13 } ; Console . WriteLine ( maxPreSum ( A , B , 0 , 0 ) ) ; } }
Sum of Bitwise AND of the sum of all leaf and non | C # program for given approach ; Structure of a Binary tree node ; Helper function to allocate a new node with the given data and left and right pointers as None ; Function to calculate the sum of bitwise AND of the sum of all leaf nodes and non - leaf nodes for each level ; Initialize a queue and append root to it ; Store the required answer ; Stores the sum of leaf nodes at the current level ; Stores the sum of non - leaf nodes at the current level ; Get the size of the queue ; Iterate for all the nodes in the queue currently ; Dequeue a node from queue ; Check if the node is a leaf node ; If true , update the leaf node sum ; Otherwise , update the non - leaf node sum ; Enqueue left and right children of removed node ; Update the answer ; Return the answer ; Driver Code ; Given Tree ; Function Call
using System ; using System . Collections . Generic ; class GFG { class TreeNode { public int val ; public TreeNode left , right ; } ; static TreeNode newNode ( int x ) { TreeNode temp = new TreeNode ( ) ; temp . val = x ; temp . left = null ; temp . right = null ; return temp ; } static int findSum ( TreeNode root ) { Queue < TreeNode > que = new Queue < TreeNode > ( ) ; que . Enqueue ( root ) ; int ans = 0 ; while ( que . Count > 0 ) { int leaf = 0 ; int nonleaf = 0 ; int length = que . Count ; while ( length > 0 ) { TreeNode temp = que . Peek ( ) ; que . Dequeue ( ) ; if ( temp . left == null && temp . right == null ) leaf += temp . val ; else nonleaf += temp . val ; if ( temp . left != null ) que . Enqueue ( temp . left ) ; if ( temp . right != null ) que . Enqueue ( temp . right ) ; length -= 1 ; } ans += ( leaf & nonleaf ) ; } return ans ; } public static void Main ( ) { TreeNode root = newNode ( 5 ) ; root . left = newNode ( 3 ) ; root . right = newNode ( 9 ) ; root . left . left = newNode ( 6 ) ; root . left . right = newNode ( 4 ) ; root . left . left . right = newNode ( 7 ) ; Console . WriteLine ( findSum ( root ) ) ; } }