codeparrot/xlcost-text-to-code huggingface dataset:
Count pairs of points having distance between them equal to integral values in a K | C # program for the above approach ; Function to find pairs whose distance between the points of is an integer value . ; Stores count of pairs whose distance between points is an integer ; Traverse the array , points [ ] ; Stores distance between points ( i , j ) ; Traverse all the points of current pair ; Update temp ; Update dist ; If dist is a perfect square ; Update ans ; Driver Code ; Given value of K ; Given points ; Given value of N ; Function Call
using System ; class GFG { static void cntPairs ( int [ , ] points , int n , int K ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int dist = 0 ; for ( int k = 0 ; k < K ; k ++ ) { int temp = ( points [ i , k ] - points [ j , k ] ) ; dist += temp * temp ; } if ( Math . Sqrt ( dist ) * Math . Sqrt ( dist ) == dist ) { ans += 1 ; } } } Console . WriteLine ( ans ) ; } public static void Main ( ) { int K = 2 ; int [ , ] points = { { 1 , 2 } , { 5 , 5 } , { - 2 , 8 } } ; int n = points . GetLength ( 0 ) ; cntPairs ( points , n , K ) ; } }
Circumradius of a Cyclic Quadrilateral using the length of Sides | C # program to find circumradius of a cyclic quadrilateral using sides ; Function to return the circumradius of a cyclic quadrilateral using sides ; Find semiperimeter ; Calculate the radius ; Driver Code ; Function call ; Print the radius
using System ; class GFG { static double Circumradius ( int a , int b , int c , int d ) { double s = ( a + b + c + d ) / 2.0 ; double radius = Math . Sqrt ( ( ( a * b ) + ( c * d ) ) * ( ( a * c ) + ( b * d ) ) * ( ( a * d ) + ( b * c ) ) / ( ( s - a ) * ( s - b ) * ( s - c ) * ( s - d ) ) ) ; return radius / 4 ; } public static void Main ( String [ ] args ) { int A = 3 ; int B = 4 ; int C = 5 ; int D = 6 ; double ans = Circumradius ( A , B , C , D ) ; Console . Write ( " { 0 : F2 } " , ans ) ; } }
Area of Triangle using Side | C # program to calculate the area of a triangle when the length of two adjacent sides and the angle between them is provided ; Function to return the area of triangle using Side - Angle - Side formula ; Driver Code ; Function Call ; Print the readonly answer
using System ; class GFG { static float Area_of_Triangle ( int a , int b , int k ) { float area = ( float ) ( ( 1 / 2.0 ) * a * b * Math . Sin ( k ) ) ; return area ; } public static void Main ( String [ ] args ) { int a = 9 ; int b = 12 ; int k = 2 ; float ans = Area_of_Triangle ( a , b , k ) ; Console . Write ( " { 0 : F1 } " , ans ) ; } }
Find the maximum angle at which we can tilt the bottle without spilling any water | C # program to find the maximum angle at which we can tilt the bottle without spilling any water ; Now we have the volume of rectangular prism a * a * b ; Now we have 2 cases ! ; Taking the tangent inverse of value d As we want to take out the required angle ; Taking the tangent inverse of value d As we want to take out the required angle ; As of now the angle is in radian . So we have to convert it in degree . ; Driver Code ; Enter the Base square side length ; Enter the Height of rectangular prism ; Enter the Base square side length
using System ; class GFG { static float find_angle ( int x , int y , int z ) { int volume = x * x * y ; float ans = 0 ; if ( z < volume / 2 ) { float d = ( float ) ( ( x * y * y ) / ( 2.0 * z ) ) ; ans = ( float ) Math . Atan ( d ) ; } else { z = volume - z ; float d = ( 2 * z ) / ( float ) ( x * x * x ) ; ans = ( float ) Math . Atan ( d ) ; } ans = ( float ) ( ( ans * 180 ) / 3.14159265 ) ; return ans ; } public static void Main ( String [ ] args ) { int x = 12 ; int y = 21 ; int z = 10 ; Console . Write ( find_angle ( x , y , z ) + " STRNEWLINE " ) ; } }
Count of distinct rectangles inscribed in an equilateral triangle | C # implementation of the approach ; Function to return the count of rectangles when n is odd ; Calculating number of dots in vertical level ; Calculating number of ways to select two points in the horizontal level i ; Multiply both to obtain the number of rectangles formed at that level ; Calculating number of dots in vertical level ; Calculating number of ways to select two points in the horizontal level i ; Multiply both to obtain the number of rectangles formed at that level ; Function to return the count of rectangles when n is even ; Driver code ; If n is odd
using System ; class GFG { static int countOdd ( int n ) { int coun = 0 , m , j , i ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( i >= 1 ) { m = ( n - i ) / 2 ; j = ( i * ( i + 1 ) ) / 2 ; coun += j * m ; } else { m = ( ( n - 1 ) - i ) / 2 ; j = ( i * ( i + 1 ) ) / 2 ; coun += j * m ; } } return coun ; } static int countEven ( int n ) { int coun = 0 , m , j , i ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( i >= 1 ) { m = ( ( n - 1 ) - i ) / 2 ; j = ( i * ( i + 1 ) ) / 2 ; coun += j * m ; } else { m = ( n - i ) / 2 ; j = ( i * ( i + 1 ) ) / 2 ; coun += j * m ; } } return coun ; } static public void Main ( ) { int n = 5 ; if ( n >= 1 ) Console . Write ( countOdd ( n ) ) ; else Console . Write ( countEven ( n ) ) ; } }
Area of the biggest ellipse inscribed within a rectangle | C # Program to find the biggest rectangle which can be inscribed within the ellipse ; Function to find the area of the rectangle ; The sides cannot be negative ; Area of the ellipse ; Driver code
using System ; class GFG { static float ellipse ( float l , float b ) { if ( l < 0 b < 0 ) return - 1 ; float x = ( float ) ( 3.14 * l * b ) / 4 ; return x ; } public static void Main ( ) { float a = 5 , b = 3 ; Console . WriteLine ( ellipse ( a , b ) ) ; } }
Determine the number of squares of unit area that a given line will pass through . | Function to return the required position ;  ; Driver Code
using System ; class GFG { static void noOfSquares ( int x1 , int y1 , int x2 , int y2 ) { int dx = Math . Abs ( x2 - x1 ) ; int dy = Math . Abs ( y2 - y1 ) ; int ans = dx + dy - __gcd ( dx , dy ) ; Console . WriteLine ( ans ) ; } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static void Main ( ) { int x1 = 1 , y1 = 1 , x2 = 4 , y2 = 3 ; noOfSquares ( x1 , y1 , x2 , y2 ) ; } }
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
using System ; class GFG { static long binomialCoeff ( int n , int k ) { long res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static long countPaths ( int x1 , int y1 , int x2 , int y2 ) { int m = Math . Abs ( x1 - x2 ) ; int n = Math . Abs ( y1 - y2 ) ; return ( binomialCoeff ( m + n , n ) ) ; } public static void Main ( ) { int x1 = 2 , y1 = 3 , x2 = 4 , y2 = 5 ; Console . Write ( countPaths ( x1 , y1 , x2 , y2 ) ) ; } }
Find the area of largest circle inscribed in ellipse | C # Program to find the area of circle ; Area of the Reuleaux triangle ; Driver code
using System ; class GFG { static double areaCircle ( double b ) { double area = ( double ) 3.1415926 * b * b ; return area ; } public static void Main ( ) { float b = 8 ; Console . WriteLine ( areaCircle ( b ) ) ; } }
Section formula for 3 D | C # 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
using System ; class GFG { static 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 ) ; Console . Write ( " ( " + x + " , ▁ " ) ; Console . Write ( y + " , ▁ " ) ; Console . WriteLine ( z + " ) " ) ; } static public void 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 ) ; } }
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
using System ; class GFG { static float findRadiusOfcircumcircle ( float n , float a ) { if ( n < 0 a < 0 ) return - 1 ; float radius = ( float ) ( a / Math . Sqrt ( 2 - ( 2 * Math . Cos ( 360 / n ) ) ) ) ; return radius ; } public static void Main ( ) { float n = 5 , a = 6 ; Console . WriteLine ( findRadiusOfcircumcircle ( n , a ) ) ; } }
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
using System ; class GFG { public static 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 = ( float ) Math . Sqrt ( p * ( p - a ) * ( p - b ) * ( p - c ) ) ; float radius = area / p ; return ( float ) ( radius ) ; } public static void Main ( ) { float a = 2 , b = 2 , c = 3 ; Console . WriteLine ( findRadiusOfIncircle ( a , b , c ) ) ; } }
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
using System ; class GFG { static float area ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 ) { double a = Math . Pow ( ( y1 * z2 - y2 * z1 ) , 2 ) + Math . Pow ( ( x1 * z2 - x2 * z1 ) , 2 ) + Math . Pow ( ( x1 * y2 - x2 * y1 ) , 2 ) ; float area = ( float ) Math . Sqrt ( a ) ; area = area / 2 ; return area ; } public static void 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 ) ; Console . WriteLine ( " Area ▁ = ▁ " + a ) ; } }
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
using System ; class GFG { static float trapezoidarea ( float r ) { if ( r < 0 ) return - 1 ; float a = ( 3 * ( float ) Math . Sqrt ( 3 ) * ( float ) Math . Pow ( r , 2 ) ) / 4 ; return a ; } public static void Main ( ) { float r = 5 ; Console . WriteLine ( " " + trapezoidarea ( r ) ) ; } }
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
using System ; class GFG { static float rectanglearea ( float r ) { if ( r < 0 ) return - 1 ; float a = r * r ; return a ; } public static void Main ( ) { float r = 5 ; Console . Write ( ( int ) rectanglearea ( r ) ) ; } }
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 code
using System ; using System . Collections . Generic ; class GFG { static int maxLines ( int n , int [ ] x1 , int [ ] y1 , int [ ] x2 , int [ ] y2 ) { HashSet < Double > s = new HashSet < Double > ( ) ; double slope ; for ( int i = 0 ; i < n ; ++ i ) { if ( x1 [ i ] == x2 [ i ] ) slope = int . MaxValue ; else slope = ( y2 [ i ] - y1 [ i ] ) * 1.0 / ( x2 [ i ] - x1 [ i ] ) * 1.0 ; s . Add ( slope ) ; } return s . Count ; } public static void Main ( ) { int n = 2 ; int [ ] x1 = { 1 , 2 } ; int [ ] y1 = { 1 , 2 } ; int [ ] x2 = { 2 , 4 } ; int [ ] y2 = { 2 , 10 } ; Console . Write ( maxLines ( n , x1 , y1 , x2 , y2 ) ) ; } }
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
using System ; class GFG { static float area ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ) { float area = ( float ) Math . Sqrt ( Math . Pow ( ( y1 * z2 - y2 * z1 ) , 2 ) + Math . Pow ( ( x1 * z2 - x2 * z1 ) , 2 ) + Math . Pow ( ( x1 * y2 - x2 * y1 ) , 2 ) ) ; return area ; } public static void 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 ) ; Console . Write ( " Area ▁ = ▁ " + a ) ; } }
Maximum possible intersection by moving centers of line segments | C # implementation of above approach ; Function to print the maximum intersection ; Case 1 ; Case 2 ; Case 3 ; Driver Code
using System ; class GFG { static int max_intersection ( int [ ] center , int length , int k ) { Array . Sort ( center ) ; 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 ; } public static void Main ( ) { int [ ] center = { 1 , 2 , 3 } ; int L = 1 ; int K = 1 ; Console . WriteLine ( max_intersection ( center , L , K ) ) ; } }
Haversine formula to find distance between two points on a sphere | C # program for the haversine formula ; distance between latitudes and longitudes ; convert to radians ; apply formulae ; Driver Code
using System ; class GFG { static double haversine ( double lat1 , double lon1 , double lat2 , double lon2 ) { double dLat = ( Math . PI / 180 ) * ( lat2 - lat1 ) ; double dLon = ( Math . PI / 180 ) * ( lon2 - lon1 ) ; lat1 = ( Math . PI / 180 ) * ( lat1 ) ; lat2 = ( Math . PI / 180 ) * ( lat2 ) ; double a = Math . Pow ( Math . Sin ( dLat / 2 ) , 2 ) + Math . Pow ( Math . Sin ( dLon / 2 ) , 2 ) * Math . Cos ( lat1 ) * Math . Cos ( lat2 ) ; double rad = 6371 ; double c = 2 * Math . Asin ( Math . Sqrt ( a ) ) ; return rad * c ; } public static void Main ( ) { double lat1 = 51.5007 ; double lon1 = 0.1246 ; double lat2 = 40.6892 ; double lon2 = 74.0445 ; Console . WriteLine ( haversine ( lat1 , lon1 , lat2 , lon2 ) + " ▁ K . M . " ) ; } }
Pentatope number | C # Program to find the nth Pentatope Number ; Function that returns nth pentatope number ; Driver Code ; For 5 th PentaTope Number ; For 11 th PentaTope Number
using System ; class GFG { static int pentatopeNum ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) * ( n + 3 ) ) / 24 ; } static public void Main ( String [ ] args ) { int n = 5 ; Console . WriteLine ( pentatopeNum ( n ) ) ; n = 11 ; Console . WriteLine ( pentatopeNum ( n ) ) ; } }
Heptagonal number | C # program to find the nth Heptagonal number ; Function to return Nth Heptagonal number ; Driver Code
using System ; class GFG { static int heptagonalNumber ( int n ) { return ( ( 5 * n * n ) - ( 3 * n ) ) / 2 ; } public static void Main ( ) { int n = 2 ; Console . WriteLine ( heptagonalNumber ( n ) ) ; n = 15 ; Console . WriteLine ( heptagonalNumber ( n ) ) ; } }
Icosidigonal number | C # program to find nth Icosidigonal number ; Function to calculate Icosidigonal number ; Formula for finding nth Icosidigonal number ; Driver Code
using System ; class GFG { static int icosidigonal_num ( int n ) { return ( 20 * n * n - 18 * n ) / 2 ; } static public void Main ( ) { int n = 4 ; Console . Write ( n + " th ▁ Icosidigonal ▁ " + " number ▁ : " ) ; Console . WriteLine ( icosidigonal_num ( n ) ) ; n = 8 ; Console . Write ( n + " th ▁ Icosidigonal ▁ " + " number ▁ : " ) ; Console . WriteLine ( icosidigonal_num ( n ) ) ; } }
Hypercube Graph | C # program to find vertices in a hypercube graph of order n ; Function to find power of 2 ; Driver code
using System ; class GfG { static int power ( int n ) { if ( n == 1 ) return 2 ; return 2 * power ( n - 1 ) ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( power ( n ) ) ; } }
Reflection of a point at 180 degree rotation of another point | C # Program to find the 180 degree reflection of one point around another point . ; Driver code
using System ; public class GFG { static void findPoint ( int x1 , int y1 , int x2 , int y2 ) { Console . WriteLine ( " ( " + ( int ) ( 2 * x2 - x1 ) + " , " + ( int ) ( 2 * y2 - y1 ) + " ▁ ) " ) ; } static public void Main ( String [ ] args ) { int x1 = 0 , y1 = 0 , x2 = 1 , y2 = 1 ; findPoint ( x1 , y1 , x2 , y2 ) ; } }
Program to check if the points are parallel to X axis or Y axis | C # program to illustrate . . 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 code
class GFG { static void parallel ( int [ , ] a ) { bool x = true , y = true ; for ( int i = 0 ; i < a . Rank - 1 ; i ++ ) { if ( a [ i , 0 ] != a [ i + 1 , 0 ] ) x = false ; if ( a [ i , 1 ] != a [ i + 1 , 1 ] ) y = false ; } if ( x ) System . Console . WriteLine ( " Parallel ▁ to ▁ Y ▁ Axis " ) ; else if ( y ) System . Console . WriteLine ( " Parallel ▁ to ▁ X ▁ Axis " ) ; else System . Console . WriteLine ( " Not ▁ parallel ▁ to ▁ X " + " ▁ and ▁ Y ▁ axis " ) ; } public static void Main ( ) { int [ , ] a = { { 1 , 2 } , { 1 , 4 } , { 1 , 6 } , { 1 , 0 } } ; parallel ( a ) ; } }
Triangular Matchstick Number | C # program to find X - th triangular matchstick number ; Driver code
using System ; class GFG { static int numberOfSticks ( int x ) { return ( 3 * x * ( x + 1 ) ) / 2 ; } public static void Main ( ) { Console . Write ( numberOfSticks ( 7 ) ) ; } }
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
using System ; class GFG { public class Point { public int x , y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int overlappingArea ( Point l1 , Point r1 , Point l2 , Point r2 ) { int area1 = Math . Abs ( l1 . x - r1 . x ) * Math . Abs ( l1 . y - r1 . y ) ; int area2 = Math . Abs ( l2 . x - r2 . x ) * Math . Abs ( l2 . y - r2 . y ) ; int x_dist = ( Math . Min ( r1 . x , r2 . x ) - Math . Max ( l1 . x , l2 . x ) ) ; int y_dist = ( Math . Min ( r1 . y , r2 . y ) - Math . Max ( l1 . y , l2 . y ) ) ; int areaI = 0 ; if ( x_dist > 0 && y_dist > 0 ) { areaI = x_dist * y_dist ; } return ( area1 + area2 - areaI ) ; } public static void Main ( String [ ] args ) { Point l1 = new Point ( 2 , 2 ) , r1 = new Point ( 5 , 7 ) ; Point l2 = new Point ( 3 , 4 ) , r2 = new Point ( 6 , 9 ) ; Console . WriteLine ( overlappingArea ( l1 , r1 , l2 , r2 ) ) ; } }
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
using System ; class GFG { static int find_Area ( int r ) { return ( 2 * r * r ) ; } public static void Main ( ) { int r = 3 ; Console . WriteLine ( " ▁ Area ▁ of ▁ square ▁ = ▁ " + find_Area ( r ) ) ; } }
Check whether triangle is valid or not if sides are given | C # program to check validity of any triangle ; Function to calculate for validity ; check condition ; Driver code ; function calling and print output
using System ; class GFG { public static int checkValidity ( int a , int b , int c ) { if ( a + b <= c a + c <= b b + c <= a ) return 0 ; else return 1 ; } public static void Main ( ) { int a = 7 , b = 10 , c = 5 ; if ( ( checkValidity ( a , b , c ) ) == 1 ) Console . Write ( " Valid " ) ; else Console . Write ( " Invalid " ) ; } }
Print Longest Palindromic Subsequence | C # program to print longest palindromic subsequence ; Returns LCS X and Y ; Following steps build L [ m + 1 , n + 1 ] in bottom up fashion . Note that L [ i , j ] contains length of LCS of X [ 0. . i - 1 ] and Y [ 0. . j - 1 ] ; Following code is used to print LCS ; Create a String length index + 1 and fill it with \ 0 ; Start from the right - most - bottom - most corner and one by one store characters in lcs [ ] ; If current character in X [ ] and Y are same , then current character is part of LCS ; Put current character in result ; reduce values of i , j and index ; } If not same , then find the larger of two and go in the direction of larger value ; Returns longest palindromic subsequence of str ; Find reverse of str ; Return LCS of str and its reverse ; convert String to character array by using toCharArray ; Driver program to test above function
using System ; public class GFG { static String lcs ( String a , String b ) { int m = a . Length ; int n = b . Length ; char [ ] X = a . ToCharArray ( ) ; char [ ] Y = b . ToCharArray ( ) ; int [ , ] L = new int [ m + 1 , n + 1 ] ; int i , j ; for ( i = 0 ; i <= m ; i ++ ) { for ( j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) { L [ i , j ] = 0 ; } else if ( X [ i - 1 ] == Y [ j - 1 ] ) { L [ i , j ] = L [ i - 1 , j - 1 ] + 1 ; } else { L [ i , j ] = Math . Max ( L [ i - 1 , j ] , L [ i , j - 1 ] ) ; } } } int index = L [ m , n ] ; char [ ] lcs = new char [ index + 1 ] ; i = m ; j = n ; while ( i > 0 && j > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { lcs [ index - 1 ] = X [ i - 1 ] ; i -- ; j -- ; index -- ; else if ( L [ i - 1 , j ] > L [ i , j - 1 ] ) { i -- ; } else { j -- ; } } String ans = " " ; for ( int x = 0 ; x < lcs . Length ; x ++ ) { ans += lcs [ x ] ; } return ans ; } static String longestPalSubseq ( String str ) { String rev = str ; rev = reverse ( rev ) ; return lcs ( str , rev ) ; } static String reverse ( String str ) { String ans = " " ; char [ ] try1 = str . ToCharArray ( ) ; for ( int i = try1 . Length - 1 ; i >= 0 ; i -- ) { ans += try1 [ i ] ; } return ans ; } public static void Main ( ) { String str = " GEEKSFORGEEKS " ; Console . Write ( longestPalSubseq ( str ) ) ; } }
Find the Surface area of a 3D figure | C # 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 code
using System ; class GFG { static int M = 3 ; static int N = 3 ; static int contribution_height ( int current , int previous ) { return Math . Abs ( current - previous ) ; } static int surfaceArea ( int [ , ] A ) { 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 ; } public static void Main ( ) { int [ , ] A = { { 1 , 3 , 4 } , { 2 , 2 , 3 } , { 1 , 2 , 4 } } ; Console . WriteLine ( surfaceArea ( A ) ) ; } }