codeparrot/xlcost-text-to-code huggingface dataset:
Numbers whose factorials end with n zeros | Binary search based C # program to find numbers with n trailing zeros . ; Function to calculate trailing zeros ; range of numbers ; binary search for first number with n trailing zeros ; Print all numbers after low with n trailing zeros . ; Print result ; Driver code
using System ; class GFG { static int trailingZeroes ( int n ) { int cnt = 0 ; while ( n > 0 ) { n /= 5 ; cnt += n ; } return cnt ; } static void binarySearch ( int n ) { int low = 0 ; int high = 1000000 ; while ( low < high ) { int mid = ( low + high ) / 2 ; int count = trailingZeroes ( mid ) ; if ( count < n ) low = mid + 1 ; else high = mid ; } int [ ] result = new int [ 1000 ] ; int k = 0 ; while ( trailingZeroes ( low ) == n ) { result [ k ] = low ; k ++ ; low ++ ; } for ( int i = 0 ; i < k ; i ++ ) Console . Write ( result [ i ] + " ▁ " ) ; } public static void Main ( ) { int n = 2 ; binarySearch ( n ) ; } }
Number of days after which tank will become empty | C # code to find number of days after which tank will become empty ; Utility method to get sum of first n numbers ; Method returns minimum number of days after which tank will become empty ; if water filling is more than capacity then after C days only tank will become empty ; initialize binary search variable ; loop until low is less than high ; if cumulate sum is greater than ( C - l ) then search on left side ; if ( C - l ) is more then search on right side ; final answer will be obtained by adding l to binary search result ; Driver code
using System ; class GFG { static int getCumulateSum ( int n ) { return ( n * ( n + 1 ) ) / 2 ; } static int minDaysToEmpty ( int C , int l ) { if ( C <= l ) return C ; int lo = 0 ; int hi = ( int ) 1e4 ; int mid ; while ( lo < hi ) { mid = ( lo + hi ) / 2 ; if ( getCumulateSum ( mid ) >= ( C - l ) ) hi = mid ; else lo = mid + 1 ; } return ( l + lo ) ; } static public void Main ( ) { int C = 5 ; int l = 2 ; Console . WriteLine ( minDaysToEmpty ( C , l ) ) ; } }
Number of days after which tank will become empty | C # code to find number of days after which tank will become empty ; Method returns minimum number of days after which tank will become empty ; Driver code
using System ; class GFG { static int minDaysToEmpty ( int C , int l ) { if ( l >= C ) return C ; double eq_root = ( Math . Sqrt ( 1 + 8 * ( C - l ) ) - 1 ) / 2 ; return ( int ) ( Math . Ceiling ( eq_root ) + l ) ; } static public void Main ( ) { Console . WriteLine ( minDaysToEmpty ( 5 , 2 ) ) ; Console . WriteLine ( minDaysToEmpty ( 6514683 , 4965 ) ) ; } }
K | C # Program to find kth element from two sorted arrays ; Driver Code
class GFG { static int kth ( int [ ] arr1 , int [ ] arr2 , int m , int n , int k ) { int [ ] sorted1 = new int [ m + n ] ; int i = 0 , j = 0 , d = 0 ; while ( i < m && j < n ) { if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ; else sorted1 [ d ++ ] = arr2 [ j ++ ] ; } while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ; while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ; return sorted1 [ k - 1 ] ; } static void Main ( ) { int [ ] arr1 = { 2 , 3 , 6 , 7 , 9 } ; int [ ] arr2 = { 1 , 4 , 8 , 10 } ; int k = 5 ; System . Console . WriteLine ( kth ( arr1 , arr2 , 5 , 4 , k ) ) ; } }
K | C # Program to find kth element from two sorted arrays ; In case we have reached end of array 1 ; In case we have reached end of array 2 ; k should never reach 0 or exceed sizes of arrays ; Compare first elements of arrays and return ; Size of array 1 is less than k / 2 ; Last element of array 1 is not kth We can directly return the ( k - m ) th element in array 2 ; Size of array 2 is less than k / 2 ; Normal comparison , move starting index of one array k / 2 to the right ; Driver code
using System ; class GFG { static int kth ( int [ ] arr1 , int [ ] arr2 , int m , int n , int k , int st1 , int st2 ) { if ( st1 == m ) { return arr2 [ st2 + k - 1 ] ; } if ( st2 == n ) { return arr1 [ st1 + k - 1 ] ; } if ( k == 0 || k > ( m - st1 ) + ( n - st2 ) ) { return - 1 ; } if ( k == 1 ) { return ( arr1 [ st1 ] < arr2 [ st2 ] ) ? arr1 [ st1 ] : arr2 [ st2 ] ; } int curr = k / 2 ; if ( curr - 1 >= m - st1 ) { if ( arr1 [ m - 1 ] < arr2 [ st2 + curr - 1 ] ) { return arr2 [ st2 + ( k - ( m - st1 ) - 1 ) ] ; } else { return kth ( arr1 , arr2 , m , n , k - curr , st1 , st2 + curr ) ; } } if ( curr - 1 >= n - st2 ) { if ( arr2 [ n - 1 ] < arr1 [ st1 + curr - 1 ] ) { return arr1 [ st1 + ( k - ( n - st2 ) - 1 ) ] ; } else { return kth ( arr1 , arr2 , m , n , k - curr , st1 + curr , st2 ) ; } } else if ( arr1 [ curr + st1 - 1 ] < arr2 [ curr + st2 - 1 ] ) { return kth ( arr1 , arr2 , m , n , k - curr , st1 + curr , st2 ) ; } else { return kth ( arr1 , arr2 , m , n , k - curr , st1 , st2 + curr ) ; } } public static void Main ( String [ ] args ) { int [ ] arr1 = { 2 , 3 , 6 , 7 , 9 } ; int [ ] arr2 = { 1 , 4 , 8 , 10 } ; int k = 5 ; int st1 = 0 , st2 = 0 ; Console . WriteLine ( kth ( arr1 , arr2 , 5 , 4 , k , st1 , st2 ) ) ; } }
Search element in a sorted matrix | C # implementation to search an element in a sorted matrix ; This function does Binary search for x in i - th row . It does the search from mat [ i ] [ j_low ] to mat [ i ] [ j_high ] ; Element found ; element not found ; Function to perform binary search on the mid values of row to get the desired pair of rows where the element can be found ; Single row matrix ; Do binary search in middle column . Condition to terminate the loop when the 2 desired rows are found ; element found ; If element is present on the mid of the two rows ; search element on 1 st half of 1 st row ; Search element on 2 nd half of 1 st row ; Search element on 1 st half of 2 nd row ; search element on 2 nd half of 2 nd row ; Driver program
using System ; class GFG { static void binarySearch ( int [ , ] mat , int i , int j_low , int j_high , int x ) { while ( j_low <= j_high ) { int j_mid = ( j_low + j_high ) / 2 ; if ( mat [ i , j_mid ] == x ) { Console . Write ( " Found ▁ at ▁ ( " + i + " , ▁ " + j_mid + " ) " ) ; return ; } else if ( mat [ i , j_mid ] > x ) j_high = j_mid - 1 ; else j_low = j_mid + 1 ; } Console . Write ( " Element ▁ no ▁ found " ) ; } static void sortedMatrixSearch ( int [ , ] mat , int n , int m , int x ) { if ( n == 1 ) { binarySearch ( mat , 0 , 0 , m - 1 , x ) ; return ; } int i_low = 0 ; int i_high = n - 1 ; int j_mid = m / 2 ; while ( ( i_low + 1 ) < i_high ) { int i_mid = ( i_low + i_high ) / 2 ; if ( mat [ i_mid , j_mid ] == x ) { Console . Write ( " Found ▁ at ▁ ( " + i_mid + " , ▁ " + j_mid + " ) " ) ; return ; } else if ( mat [ i_mid , j_mid ] > x ) i_high = i_mid ; else i_low = i_mid ; } if ( mat [ i_low , j_mid ] == x ) Console . Write ( " Found ▁ at ▁ ( " + i_low + " , " + j_mid + " ) " ) ; else if ( mat [ i_low + 1 , j_mid ] == x ) Console . Write ( " Found ▁ at ▁ ( " + ( i_low + 1 ) + " , ▁ " + j_mid + " ) " ) ; else if ( x <= mat [ i_low , j_mid - 1 ] ) binarySearch ( mat , i_low , 0 , j_mid - 1 , x ) ; else if ( x >= mat [ i_low , j_mid + 1 ] && x <= mat [ i_low , m - 1 ] ) binarySearch ( mat , i_low , j_mid + 1 , m - 1 , x ) ; else if ( x <= mat [ i_low + 1 , j_mid - 1 ] ) binarySearch ( mat , i_low + 1 , 0 , j_mid - 1 , x ) ; else binarySearch ( mat , i_low + 1 , j_mid + 1 , m - 1 , x ) ; } public static void Main ( String [ ] args ) { int n = 4 , m = 5 , x = 8 ; int [ , ] mat = { { 0 , 6 , 8 , 9 , 11 } , { 20 , 22 , 28 , 29 , 31 } , { 36 , 38 , 50 , 61 , 63 } , { 64 , 66 , 100 , 122 , 128 } } ; sortedMatrixSearch ( mat , n , m , x ) ; } }
Minimum difference between adjacent elements of array which contain elements from each row of a matrix | C # program to find the minimum absolute difference between any of the adjacent elements of an array which is created by picking one element from each row of the matrix ; Return smallest element greater than or equal to the current element . ; Return the minimum absolute difference adjacent elements of array ; Sort each row of the matrix . ; For each matrix element ; Search smallest element in the next row which is greater than or equal to the current element ; largest element which is smaller than the current element in the next row must be just before smallest element which is greater than or equal to the current element because rows are sorted . ; Driver code
using System ; class GFG { static public int R = 2 ; static public int C = 2 ; static int bsearch ( int low , int high , int n , int [ ] arr ) { int mid = ( low + high ) / 2 ; if ( low <= high ) { if ( arr [ mid ] < n ) return bsearch ( mid + 1 , high , n , arr ) ; return bsearch ( low , mid - 1 , n , arr ) ; } return low ; } public static int [ ] GetRow ( int [ , ] matrix , int row ) { var rowLength = matrix . GetLength ( 1 ) ; var rowVector = new int [ rowLength ] ; for ( var i = 0 ; i < rowLength ; i ++ ) rowVector [ i ] = matrix [ row , i ] ; return rowVector ; } static int mindiff ( int [ , ] arr , int n , int m ) { for ( int i = 0 ; i < n ; i ++ ) Array . Sort ( GetRow ( arr , i ) ) ; int ans = + 2147483647 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int p = bsearch ( 0 , m - 1 , arr [ i , j ] , GetRow ( arr , i + 1 ) ) ; ans = Math . Min ( ans , Math . Abs ( arr [ i + 1 , p ] - arr [ i , j ] ) ) ; if ( p - 1 >= 0 ) ans = Math . Min ( ans , Math . Abs ( arr [ i + 1 , p - 1 ] - arr [ i , j ] ) ) ; } } return ans ; } public static void Main ( String [ ] args ) { int [ , ] m = { { 8 , 5 } , { 6 , 8 } } ; Console . WriteLine ( mindiff ( m , R , C ) ) ; } }
Find bitonic point in given bitonic sequence | C # program to find bitonic point in a bitonic array . ; Function to find bitonic point using binary search ; base condition to check if arr [ mid ] is bitonic point or not ; We assume that sequence is bitonic . We go to right subarray if middle point is part of increasing subsequence . Else we go to left subarray . ; Driver program
using System ; class GFG { static int binarySearch ( int [ ] arr , int left , int right ) { if ( left <= right ) { int mid = ( left + right ) / 2 ; if ( arr [ mid - 1 ] < arr [ mid ] && arr [ mid ] > arr [ mid + 1 ] ) return mid ; if ( arr [ mid ] < arr [ mid + 1 ] ) return binarySearch ( arr , mid + 1 , right ) ; else return binarySearch ( arr , left , mid - 1 ) ; } return - 1 ; } public static void Main ( ) { int [ ] arr = { 6 , 7 , 8 , 11 , 9 , 5 , 2 , 1 } ; int n = arr . Length ; int index = binarySearch ( arr , 1 , n - 2 ) ; if ( index != - 1 ) Console . Write ( arr [ index ] ) ; } }
Find the only repeating element in a sorted array of size n | C # program to find the only repeating element in an array of size n and elements from range 1 to n - 1. ; Returns index of second appearance of a repeating element . The function assumes that array elements are in range from 1 to n - 1. ; low = 0 , high = n - 1 ; ; Check if the mid element is the repeating one ; If mid element is not at its position that means the repeated element is in left ; If mid is at proper position then repeated one is in right . ; Driver method
using System ; class Test { static int findRepeatingElement ( int [ ] arr , int low , int high ) { if ( low > high ) return - 1 ; int mid = ( low + high ) / 2 ; if ( arr [ mid ] != mid + 1 ) { if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ; return findRepeatingElement ( arr , low , mid - 1 ) ; } return findRepeatingElement ( arr , mid + 1 , high ) ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 3 , 4 , 5 } ; int index = findRepeatingElement ( arr , 0 , arr . Length - 1 ) ; if ( index != - 1 ) Console . Write ( arr [ index ] ) ; } }
Find cubic root of a number | C # program to find cubic root of a number using Binary Search ; Returns the absolute value of n - mid * mid * mid ; Returns cube root of a no . n ; Set start and end for binary search ; Set precision ; If error is less than e then mid is our answer so return mid ; If mid * mid * mid is greater than n set end = mid ; If mid * mid * mid is less than n set start = mid ; Driver Code
using System ; class GFG { static double diff ( double n , double mid ) { if ( n > ( mid * mid * mid ) ) return ( n - ( mid * mid * mid ) ) ; else return ( ( mid * mid * mid ) - n ) ; } static double cubicRoot ( double n ) { double start = 0 , end = n ; double e = 0.0000001 ; while ( true ) { double mid = ( start + end ) / 2 ; double error = diff ( n , mid ) ; if ( error <= e ) return mid ; if ( ( mid * mid * mid ) > n ) end = mid ; else start = mid ; } } public static void Main ( ) { double n = 3 ; Console . Write ( " Cube ▁ root ▁ of ▁ " + n + " ▁ is ▁ " + cubicRoot ( n ) ) ; } }
Find frequency of each element in a limited range array in less than O ( n ) time | C # program to count number of occurrences of each element in the array in less than O ( n ) time ; A recursive function to count number of occurrences for each element in the array without traversing the whole array ; If element at index low is equal to element at index high in the array ; increment the frequency of the element by count of elements between high and low ; Find mid and recurse for left and right subarray ; A wrapper over recursive function findFrequencyUtil ( ) . It print number of occurrences of each element in the array . ; create a empty vector to store frequencies and initialize it by 0. Size of vector is maximum value ( which is last value in sorted array ) plus 1. ; Fill the vector with frequency ; Print the frequencies ; Driver Code
using System ; class GFG { static void findFrequencyUtil ( int [ ] arr , int low , int high , int [ ] freq ) { if ( arr [ low ] == arr [ high ] ) { freq [ arr [ low ] ] += high - low + 1 ; } else { int mid = ( low + high ) / 2 ; findFrequencyUtil ( arr , low , mid , freq ) ; findFrequencyUtil ( arr , mid + 1 , high , freq ) ; } } static void findFrequency ( int [ ] arr , int n ) { int [ ] freq = new int [ arr [ n - 1 ] + 1 ] ; findFrequencyUtil ( arr , 0 , n - 1 , freq ) ; for ( int i = 0 ; i <= arr [ n - 1 ] ; i ++ ) if ( freq [ i ] != 0 ) Console . WriteLine ( " Element ▁ " + i + " ▁ occurs ▁ " + freq [ i ] + " ▁ times " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 } ; int n = arr . Length ; findFrequency ( arr , n ) ; } }
Square root of an integer | A C # program to find floor ( sqrt ( x ) ) ; Returns floor of square root of x ; Base cases ; Starting from 1 , try all numbers until i * i is greater than or equal to x . ; Driver Code
using System ; class GFG { static int floorSqrt ( int x ) { if ( x == 0 x == 1 ) return x ; int i = 1 , result = 1 ; while ( result <= x ) { i ++ ; result = i * i ; } return i - 1 ; } static public void Main ( ) { int x = 11 ; Console . WriteLine ( floorSqrt ( x ) ) ; } }
Maximum number of overlapping rectangles with at least one common point | C # program for the above approach ; Function to find the maximum number of overlapping rectangles ; Stores the maximum count of overlapping rectangles ; Stores the X and Y coordinates ; Iterate over all pairs of Xs and Ys ; Store the count for the current X and Y ; Update the maximum count of rectangles ; Returns the total count ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void maxOverlappingRectangles ( int [ ] x1 , int [ ] y1 , int [ ] x2 , int [ ] y2 , int N ) { int max_rectangles = 0 ; List < int > X = new List < int > ( ) ; List < int > Y = new List < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { X . Add ( x1 [ i ] ) ; X . Add ( x2 [ i ] - 1 ) ; Y . Add ( y1 [ i ] ) ; Y . Add ( y2 [ i ] - 1 ) ; } for ( int i = 0 ; i < X . Count ; i ++ ) { for ( int j = 0 ; j < Y . Count ; j ++ ) { int cnt = 0 ; for ( int k = 0 ; k < N ; k ++ ) { if ( X [ i ] >= x1 [ k ] && X [ i ] + 1 <= x2 [ k ] && Y [ j ] >= y1 [ k ] && Y [ j ] + 1 <= y2 [ k ] ) { cnt ++ ; } } max_rectangles = Math . Max ( max_rectangles , cnt ) ; } } Console . WriteLine ( max_rectangles ) ; } public static void Main ( ) { int [ ] x1 = { 0 , 50 } ; int [ ] y1 = { 0 , 50 } ; int [ ] x2 = { 100 , 60 } ; int [ ] y2 = { 100 , 60 } ; int N = x1 . Length ; maxOverlappingRectangles ( x1 , y1 , x2 , y2 , N ) ; } }
Check if it is possible to reach the point ( X , Y ) using distances given in an array | C # program for the above approach ; Function to check if the point ( X , Y ) is reachable from ( 0 , 0 ) or not ; Find the Euclidian Distance ; Calculate the maximum distance ; Case 1. ; Case 2. ; Otherwise , check for the polygon condition for each side ; Otherwise , print Yes ; Driver Code
using System ; class GFG { static int isPossibleToReach ( int [ ] A , int N , int X , int Y ) { double distance = Math . Sqrt ( ( X * X + Y * Y ) ) ; double mx = 0 ; for ( int i = 0 ; i < N ; i ++ ) { mx += ( A [ i ] ) ; } if ( mx < distance ) { Console . Write ( " NO " ) ; return 0 ; } if ( ( mx - distance ) < 0.000001 ) { Console . Write ( " YES " ) ; return 0 ; } for ( int i = 0 ; i < N ; i ++ ) { if ( distance + mx < 2 * A [ i ] ) { Console . Write ( " No " ) ; return 0 ; } } Console . Write ( " Yes " ) ; return 0 ; } static public void Main ( ) { int [ ] A = { 2 , 5 } ; int X = 5 , Y = 4 ; int N = A . Length ; isPossibleToReach ( A , N , X , Y ) ; } }
Check if it is possible to reach ( X , Y ) from origin such that in each ith move increment x or y coordinate with 3 ^ i | C # program for the above approach ; Function to find whether ( 0 , 0 ) can be reached from ( X , Y ) by decrementing 3 ^ i at each ith step ; Termination Condition ; Otherwise , recursively call by decrementing 3 ^ i at each step ; Driver Code
using System ; class GFG { static Boolean canReach ( int X , int Y , int steps ) { if ( X == 0 && Y == 0 ) { return true ; } if ( X < 0 Y < 0 ) { return false ; } return ( canReach ( X - ( int ) Math . Pow ( 3 , steps ) , Y , steps + 1 ) | canReach ( X , Y - ( int ) Math . Pow ( 3 , steps ) , steps + 1 ) ) ; } public static void Main ( String [ ] args ) { int X = 10 , Y = 30 ; if ( canReach ( X , Y , 0 ) ) { Console . Write ( " YES " + " STRNEWLINE " ) ; } else Console . Write ( " NO " + " STRNEWLINE " ) ; } }
Check if it is possible to reach ( X , Y ) from origin such that in each ith move increment x or y coordinate with 3 ^ i | C # program for the above approach ; Function to find whether ( 0 , 0 ) can be reached from ( X , Y ) by decrementing 3 ^ i at each ith step ; Stores the number of steps performed to reach ( X , Y ) ; Value of X in base 3 ; Value of Y in base 3 ; Check if any has value 2 ; If both have value 1 ; If both have value 0 ; Otherwise , return true ; Driver Code
using System ; public class GFG { static bool canReach ( int X , int Y ) { int steps = 0 ; while ( X != 0 Y != 0 ) { int pos1 = X % 3 ; int pos2 = Y % 3 ; if ( pos1 == 2 pos2 == 2 ) { return false ; } if ( pos1 == 1 && pos2 == 1 ) { return false ; } if ( pos1 == 0 && pos2 == 0 ) { return false ; } X /= 3 ; Y /= 3 ; steps ++ ; } return true ; } public static void Main ( String [ ] args ) { int X = 10 , Y = 30 ; if ( canReach ( X , Y ) ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }
Program to calculate Surface Area of Ellipsoid | C # program of the above approach ; Function to find the surface area of the given Ellipsoid ; Formula to find surface area of an Ellipsoid ; Print the area ; Driver Code
using System ; class GFG { static void findArea ( double a , double b , double c ) { double area = 4 * 3.141592653 * Math . Pow ( ( Math . Pow ( a * b , 1.6 ) + Math . Pow ( a * c , 1.6 ) + Math . Pow ( b * c , 1.6 ) ) / 3 , 1 / 1.6 ) ; Console . Write ( Math . Round ( area , 2 ) ) ; } public static void Main ( String [ ] args ) { double A = 11 , B = 12 , C = 13 ; findArea ( A , B , C ) ; } }
Descartes ' Circle Theorem with implementation | C # implementation of the above formulae ; Function to find the fourth circle 's  when three radius are given ; Driver code ; Radius of three circles ; Calculation of r4 using formula given above
using System ; class GFG { static double findRadius ( double r1 , double r2 , double r3 ) { double r4 = ( r1 * r2 * r3 ) / ( r1 * r2 + r2 * r3 + r1 * r3 + 2.0 * Math . Sqrt ( r1 * r2 * r3 * ( r1 + r2 + r3 ) ) ) ; return r4 ; } public static void Main ( String [ ] args ) { double r1 = 1 ; double r2 = 1 ; double r3 = 1 ; double r4 = Math . Round ( findRadius ( r1 , r2 , r3 ) , 6 ) ; Console . Write ( " The ▁ radius ▁ of ▁ fourth ▁ circle : ▁ " + r4 ) ; } }
Make N pairs from Array as ( X , Y ) coordinate point that are enclosed inside a minimum area rectangle | C # program for the above approach ; Function to make N pairs of coordinates such that they are enclosed in a minimum area rectangle with sides parallel to the X and Y axes ; A variable to store the answer ; For the case where the maximum and minimum are in different partitions ; For the case where the maximum and minimum are in the same partition ; Return the answer ; Driver code ; Given Input ; Function call
using System ; class GFG { public static int minimumRectangleArea ( int [ ] A , int N ) { int ans ; Array . Sort ( A ) ; ans = ( A [ N - 1 ] - A [ 0 ] ) * ( A [ 2 * N - 1 ] - A [ N ] ) ; for ( int i = 1 ; i < N ; i ++ ) ans = Math . Min ( ans , ( A [ 2 * N - 1 ] - A [ 0 ] ) * ( A [ i + N - 1 ] - A [ i ] ) ) ; return ans ; } public static void Main ( String [ ] args ) { int [ ] A = { 2 , 4 , 1 , 5 , 3 , 6 , 7 , 8 } ; int N = A . Length ; N = ( int ) N / 2 ; Console . Write ( minimumRectangleArea ( A , N ) ) ; } }
Program to find the length of Latus Rectum of a Hyperbola | C # program for the above approach ; Function to calculate the length of the latus rectum of a hyperbola ; Store the length of major axis ; Store the length of minor axis ; Store the length of the latus rectum ; Return the length of the latus rectum ; Driver Code
using System ; class GFG { static double lengthOfLatusRectum ( double A , double B ) { double major = 2.0 * A ; double minor = 2.0 * B ; double latus_rectum = ( minor * minor ) / major ; return latus_rectum ; } public static void Main ( ) { double A = 3.0 , B = 2.0 ; Console . WriteLine ( lengthOfLatusRectum ( A , B ) ) ; } }
Length of intercept cut off from a line by a Circle | C # program for the above approach ; Function to find the radius of a circle ; g and f are the coordinates of the center ; Case of invalid circle ; Apply the radius formula ; Function to find the perpendicular distance between circle center and the line ; Store the coordinates of center ; Stores the perpendicular distance between the line and the point ; Invalid Case ; Return the distance ; Function to find the length of intercept cut off from a line by a circle ; Calculate the value of radius ; Calculate the perpendicular distance between line and center ; Invalid Case ; If line do not cut circle ; Print the intercept length ; Driver code ; Given Input ; Function Call
using System ; class GFG { static double radius ( int a , int b , int c ) { int g = a / 2 ; int f = b / 2 ; if ( g * g + f * f - c < 0 ) return ( - 1 ) ; return ( Math . Sqrt ( g * g + f * f - c ) ) ; } static double centerDistanceFromLine ( int a , int b , int i , int j , int k ) { int g = a / 2 ; int f = b / 2 ; double distance = Math . Abs ( i * g + j * f + k ) / ( Math . Sqrt ( i * i + j * j ) ) ; if ( distance < 0 ) return ( - 1 ) ; return distance ; } static void interceptLength ( int a , int b , int c , int i , int j , int k ) { double rad = radius ( a , b , c ) ; double dist = centerDistanceFromLine ( a , b , i , j , k ) ; if ( rad < 0 dist < 0 ) { Console . WriteLine ( " circle ▁ not ▁ possible " ) ; return ; } if ( dist > rad ) { Console . WriteLine ( " Line ▁ not ▁ cutting ▁ circle " ) ; } else Console . WriteLine ( 2 * Math . Sqrt ( rad * rad - dist * dist ) ) ; } public static void Main ( String [ ] args ) { int a = 0 , b = 0 , c = - 4 ; int i = 2 , j = - 1 , k = 1 ; interceptLength ( a , b , c , i , j , k ) ; } }