codeparrot/xlcost-text-to-code huggingface dataset:
Divide array into increasing and decreasing subsequence without changing the order | C # implementation of the approach ; Function to print strictly increasing and strictly decreasing sequence if possible ; Arrays to store strictly increasing and decreasing sequence ; Initializing last element of both sequence ; Iterating through the array ; If current element can be appended to both the sequences ; If next element is greater than the current element Then append it to the strictly increasing array ; Otherwise append it to the strictly decreasing array ; If current element can be appended to the increasing sequence only ; If current element can be appended to the decreasing sequence only ; Else we can not make such sequences from the given array ; Print the required sequences ; Driver Code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void Find_Sequence ( int [ ] arr , int n ) { ArrayList inc_arr = new ArrayList ( ) ; ArrayList dec_arr = new ArrayList ( ) ; int flag = 0 ; long inc = - 1 , dec = ( long ) 1e7 ; for ( int i = 0 ; i < n ; i ++ ) { if ( inc < arr [ i ] && arr [ i ] < dec ) { if ( arr [ i ] < arr [ i + 1 ] ) { inc = arr [ i ] ; inc_arr . Add ( arr [ i ] ) ; } else { dec = arr [ i ] ; dec_arr . Add ( arr [ i ] ) ; } } else if ( inc < arr [ i ] ) { inc = arr [ i ] ; inc_arr . Add ( arr [ i ] ) ; } else if ( dec > arr [ i ] ) { dec = arr [ i ] ; dec_arr . Add ( arr [ i ] ) ; } else { Console . Write ( - 1 ) ; flag = 1 ; break ; } } if ( flag == 0 ) { foreach ( int i in inc_arr ) Console . Write ( i + " ▁ " ) ; Console . Write ( ' STRNEWLINE ' ) ; foreach ( int i in dec_arr ) Console . Write ( i + " ▁ " ) ; Console . Write ( ' STRNEWLINE ' ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 5 , 1 , 3 , 6 , 8 , 2 , 9 , 0 , 10 } ; int n = arr . Length ; Find_Sequence ( arr , n ) ; } }
Find the sum of digits of a number at even and odd places | C # implementation of the approach ; Function to return the reverse of a number ; Function to find the sum of the odd and even positioned digits in a number ; If c is even number then it means digit extracted is at even place ; Driver code
using System ; class GFG { static int reverse ( int n ) { int rev = 0 ; while ( n != 0 ) { rev = ( rev * 10 ) + ( n % 10 ) ; n /= 10 ; } return rev ; } static void getSum ( int n ) { n = reverse ( n ) ; int sumOdd = 0 , sumEven = 0 , c = 1 ; while ( n != 0 ) { if ( c % 2 == 0 ) sumEven += n % 10 ; else sumOdd += n % 10 ; n /= 10 ; c ++ ; } Console . WriteLine ( " Sum ▁ odd ▁ = ▁ " + sumOdd ) ; Console . WriteLine ( " Sum ▁ even ▁ = ▁ " + sumEven ) ; } public static void Main ( ) { int n = 457892 ; getSum ( n ) ; } }
Find the sum of digits of a number at even and odd places | C # implementation of the above approach ; Function to find the sum of the odd and even positioned digits in a number ; If n is odd then the last digit will be odd positioned ; To store the respective sums ; While there are digits left process ; If current digit is odd positioned ; Even positioned digit ; Invert state ; Remove last digit ; Driver code
using System ; class GFG { static void getSum ( int n ) { bool isOdd = ( n % 2 == 1 ) ? true : false ; int sumOdd = 0 , sumEven = 0 ; while ( n != 0 ) { if ( isOdd ) sumOdd += n % 10 ; else sumEven += n % 10 ; isOdd = ! isOdd ; n /= 10 ; } Console . WriteLine ( " Sum ▁ odd ▁ = ▁ " + sumOdd ) ; Console . Write ( " Sum ▁ even ▁ = ▁ " + sumEven ) ; } static public void Main ( ) { int n = 457892 ; getSum ( n ) ; } }
Count the number of currency notes needed | C # implementation of the approach ; Function to return the amount of notes with value A required ; If possible ; Driver code
using System ; class GFG { static int bankNotes ( int A , int B , int S , int N ) { int numerator = S - ( B * N ) ; int denominator = A - B ; if ( numerator % denominator == 0 ) return ( numerator / denominator ) ; return - 1 ; } public static void Main ( ) { int A = 1 , B = 2 , S = 7 , N = 5 ; Console . Write ( bankNotes ( A , B , S , N ) ) ; } }
Divide a number into two parts | C # implementation of the approach ; Function to print the two parts ; Find the position of 4 ; If current character is not '4' but appears after the first occurrence of '4' ; Print both the parts ; Driver code
using System ; class GfG { static void twoParts ( string str ) { int flag = 0 ; string a = " " ; char [ ] gfg = str . ToCharArray ( ) ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( gfg [ i ] == '4' ) { gfg [ i ] = '3' ; a += '1' ; flag = 1 ; } else if ( flag != 0 ) a += '0' ; } str = new String ( gfg ) ; Console . WriteLine ( str + " ▁ " + a ) ; } static void Main ( ) { string str = "9441" ; twoParts ( str ) ; } }
Length of the longest substring with no consecutive same letters | C # implementation of the approach ; Function to return the length of the required sub - string ; Get the length of the string ; Iterate in the string ; Check for not consecutive ; If cnt greater than maxi ; Re - initialize ; Check after iteration is complete ; Driver code
using System ; class GfG { static int longestSubstring ( string s ) { int cnt = 1 , maxi = 1 ; int n = s . Length ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] != s [ i - 1 ] ) cnt ++ ; else { maxi = Math . Max ( cnt , maxi ) ; cnt = 1 ; } } maxi = Math . Max ( cnt , maxi ) ; return maxi ; } static void Main ( ) { string s = " ccccdeededff " ; Console . WriteLine ( longestSubstring ( s ) ) ; } }
Minimum number of changes such that elements are first Negative and then Positive | C # implementation of the approach ; Function to return the count of minimum operations required ; To store the count of negative integers on the right of the current index ( inclusive ) ; Find the count of negative integers on the right ; If current element is negative ; To store the count of positive elements ; Find the positive integers on the left ; If current element is positive ; Update the answer ; Return the required answer ; Driver code
using System ; class GFG { static int Minimum_Operations ( int [ ] a , int n ) { int [ ] np = new int [ n + 1 ] ; np [ n ] = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { np [ i ] = np [ i + 1 ] ; if ( a [ i ] <= 0 ) np [ i ] ++ ; } int pos = 0 ; int ans = n ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] >= 0 ) pos ++ ; ans = Math . Min ( ans , pos + np [ i + 1 ] ) ; } return ans ; } static void Main ( ) { int [ ] a = { - 1 , 0 , 1 , 2 } ; int n = a . Length ; Console . WriteLine ( Minimum_Operations ( a , n ) ) ; } }
Sum of elements in an array whose difference with the mean of another array is less than k | C # implementation of the approach ; Function for finding sum of elements whose diff with mean is not more than k ; Find the mean of second array ; Find sum of elements from array1 whose difference with mean in not more than k ; Return result ; Driver code
using System ; class GFG { static int findSumofEle ( int [ ] arr1 , int m , int [ ] arr2 , int n , int k ) { float arraySum = 0 ; for ( int i = 0 ; i < n ; i ++ ) arraySum += arr2 [ i ] ; float mean = arraySum / n ; int sumOfElements = 0 ; float difference = 0 ; for ( int i = 0 ; i < m ; i ++ ) { difference = arr1 [ i ] - mean ; if ( ( difference < 0 ) && ( k > ( - 1 ) * difference ) ) { sumOfElements += arr1 [ i ] ; } if ( ( difference >= 0 ) && ( k > difference ) ) { sumOfElements += arr1 [ i ] ; } } return sumOfElements ; } static void Main ( ) { int [ ] arr1 = { 1 , 2 , 3 , 4 , 7 , 9 } ; int [ ] arr2 = { 0 , 1 , 2 , 1 , 1 , 4 } ; int k = 2 ; int m = arr1 . Length ; int n = arr2 . Length ; Console . WriteLine ( findSumofEle ( arr1 , m , arr2 , n , k ) ) ; } }
Find n positive integers that satisfy the given equations | C # implementation of the approach ; Function to find n positive integers that satisfy the given conditions ; To store n positive integers ; Place N - 1 one 's ; If can not place ( y - ( n - 1 ) ) as the Nth integer ; Place Nth integer ; To store the sum of squares of N integers ; If it is less than x ; Print the required integers ; Driver code
using System ; using System . Collections ; class GFG { static void findIntegers ( int n , int x , int y ) { ArrayList ans = new ArrayList ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) ans . Add ( 1 ) ; if ( y - ( n - 1 ) <= 0 ) { Console . Write ( " - 1" ) ; return ; } ans . Add ( y - ( n - 1 ) ) ; int store = 0 ; for ( int i = 0 ; i < n ; i ++ ) store += ( int ) ans [ i ] * ( int ) ans [ i ] ; if ( store < x ) { Console . Write ( " - 1" ) ; return ; } for ( int i = 0 ; i < n ; i ++ ) Console . Write ( ( int ) ans [ i ] + " ▁ " ) ; } static void Main ( ) { int n = 3 , x = 254 , y = 18 ; findIntegers ( n , x , y ) ; } }
Find the minimum number of steps to reach M from N | C # program to find minimum number of steps to reach M from N ; Function to find a minimum number of steps to reach M from N ; Continue till m is greater than n ; If m is odd ; add one ; divide m by 2 ; Return the required answer ; Driver code
using System ; class GFG { static int Minsteps ( int n , int m ) { int ans = 0 ; while ( m > n ) { if ( m % 2 != 0 ) { m ++ ; ans ++ ; } m /= 2 ; ans ++ ; } return ans + n - m ; } public static void Main ( ) { int n = 4 , m = 6 ; Console . WriteLine ( Minsteps ( n , m ) ) ; } }
Find the number of jumps to reach X in the number line from zero | C # program to find the number of jumps to reach X in the number line from zero ; Utility function to calculate sum of numbers from 1 to x ; Function to find the number of jumps to reach X in the number line from zero ; First make number positive Answer will be same either it is Positive or negative ; To store required answer ; Continue till number is lesser or not in same parity ; Return the required answer ; Driver code
using System ; class GFG { static int getsum ( int x ) { return ( x * ( x + 1 ) ) / 2 ; } static int countJumps ( int n ) { n = Math . Abs ( n ) ; int ans = 0 ; while ( getsum ( ans ) < n || ( ( getsum ( ans ) - n ) & 1 ) > 0 ) ans ++ ; return ans ; } static void Main ( ) { int n = 9 ; Console . WriteLine ( countJumps ( n ) ) ; } }
Maximum number of candies that can be bought | C # implementation of the approach ; Function to return the maximum candies that can be bought ; Buy all the candies of the last type ; Starting from second last ; Amount of candies of the current type that can be bought ; Add candies of current type that can be bought ; Update the previous bought amount ; Driver code
using System ; class GFG { static int maxCandies ( int [ ] arr , int n ) { int prevBought = arr [ n - 1 ] ; int candies = prevBought ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int x = Math . Min ( prevBought - 1 , arr [ i ] ) ; if ( x >= 0 ) { candies += x ; prevBought = x ; } } return candies ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 1 , 3 , 6 } ; int n = arr . Length ; Console . WriteLine ( maxCandies ( arr , n ) ) ; } }
Replace all elements by difference of sums of positive and negative numbers after that element | C # program to implement above approach ; Function to print the array elements ; Function to replace all elements with absolute difference of absolute sums of positive and negative elements ; Calculate absolute sums of positive and negative elements in range i + 1 to N ; calculate difference of both sums ; replace i - th elements with absolute difference ; Driver code
using System ; class GFG { static void printArray ( int N , int [ ] arr ) { for ( int i = 0 ; i < N ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } static void replacedArray ( int N , int [ ] arr ) { int pos_sum , neg_sum , i , j , diff ; for ( i = 0 ; i < N ; i ++ ) { pos_sum = 0 ; neg_sum = 0 ; for ( j = i + 1 ; j < N ; j ++ ) { if ( arr [ j ] > 0 ) pos_sum += arr [ j ] ; else neg_sum += arr [ j ] ; } diff = Math . Abs ( pos_sum ) - Math . Abs ( neg_sum ) ; arr [ i ] = Math . Abs ( diff ) ; } } static void Main ( ) { int N = 5 ; int [ ] arr = { 1 , - 1 , 2 , 3 , - 2 } ; replacedArray ( N , arr ) ; printArray ( N , arr ) ; N = 6 ; int [ ] arr1 = { - 3 , - 4 , - 2 , 5 , 1 , - 2 } ; replacedArray ( N , arr1 ) ; printArray ( N , arr1 ) ; } }
Minimum cuts required to convert a palindromic string to a different palindromic string | C # program to solve the above problem ; Function to check if string is palindrome or not ; Function to check if it is possible to get result by making just one cut ; Appending last element in front ; Removing last element ; Checking whether string s2 is palindrome and different from s . ; If length is <= 3 then it is impossible ; Array to store frequency of characters ; Store count of characters in a array ; Condition for edge cases ; Return 1 if it is possible to get palindromic string in just one cut . Else we can always reached in two cuttings . ; Driver Code
using System ; using System . Linq ; class GFG { static bool isPalindrome ( string s ) { for ( int i = 0 ; i < s . Length ; ++ i ) { if ( s [ i ] != s [ s . Length - i - 1 ] ) { return false ; } } return true ; } static bool ans ( string s ) { string s2 = s ; for ( int i = 0 ; i < s . Length ; ++ i ) { s2 = s2 [ s2 . Length - 1 ] + s2 ; s2 = s2 . Substring ( 0 , s2 . Length - 1 ) ; if ( ( s == null ? s2 != null : ! s . Equals ( s2 ) ) && isPalindrome ( s2 ) ) { return true ; } } return false ; } static int solve ( string s ) { if ( s . Length <= 3 ) { return - 1 ; } int [ ] cnt = new int [ 25 ] ; for ( int i = 0 ; i < s . Length ; i ++ ) { cnt [ s [ i ] - ' a ' ] ++ ; } if ( cnt . Max ( ) >= ( s . Length - 1 ) ) { return - 1 ; } else { return ( ans ( s ) ? 1 : 2 ) ; } } static void Main ( ) { string s = " nolon " ; Console . WriteLine ( solve ( s ) ) ; } }
Minimum cuts required to convert a palindromic string to a different palindromic string | C # program to solve the above problem ; Recursive function to find minimum number of cuts if length of String is even ; If length is odd then return 2 ; To check if half of palindromic String is itself a palindrome ; If not then return 1 ; Else call function with half palindromic String ; Function to find minimum number of cuts If length of String is odd ; If length is <= 3 then it is impossible ; Array to store frequency of characters ; Store count of characters in a array ; Condition for edge cases ; If length is even ; If length is odd ; Driver Code
using System ; using System . Linq ; class GFG { static int solveEven ( String s ) { if ( s . Length % 2 == 1 ) { return 2 ; } String ls = s . Substring ( 0 , s . Length / 2 ) ; String rs = s . Substring ( s . Length / 2 , s . Length ) ; if ( ls != rs ) { return 1 ; } return solveEven ( ls ) ; } static int solveOdd ( String s ) { return 2 ; } static int solve ( String s ) { if ( s . Length <= 3 ) { return - 1 ; } int [ ] cnt = new int [ 25 ] ; for ( int i = 0 ; i < s . Length ; i ++ ) { cnt [ s [ i ] - ' a ' ] ++ ; } if ( cnt . Max ( ) >= s . Length - 1 ) { return - 1 ; } if ( s . Length % 2 == 0 ) { return solveEven ( s ) ; } if ( s . Length % 2 == 1 ) { return solveOdd ( s ) ; } return int . MinValue ; } public static void Main ( ) { String s = " nolon " ; Console . WriteLine ( solve ( s ) ) ; } }
Minimum changes required such that the string satisfies the given condition | C # implementation of the approach ; Function to return the minimum changes required ; To store the count of minimum changes , number of ones and the number of zeroes ; First character has to be '1' ; If condition fails changes need to be made ; Return the required count ; Driver code
using System ; class GFG { static int minChanges ( char [ ] str , int n ) { int count = 0 , zeros = 0 , ones = 0 ; if ( str [ 0 ] != '1' ) { count ++ ; ones ++ ; } for ( int i = 1 ; i < n ; i ++ ) { if ( str [ i ] == '0' ) zeros ++ ; else ones ++ ; if ( zeros > ones ) { zeros -- ; ones ++ ; count ++ ; } } return count ; } public static void Main ( String [ ] args ) { char [ ] str = "0000" . ToCharArray ( ) ; int n = str . Length ; Console . Write ( minChanges ( str , n ) ) ; } }
Count possible moves in the given direction in a grid | C # implementation of the above approach ; Function to return the count of possible steps in a single direction ; It can cover infinite steps ; We are approaching towards X = N ; We are approaching towards X = 1 ; Function to return the count of steps ; Take the minimum of both moves independently ; Update count and current positions ; Driver code
using System ; class GFG { static int steps ( int cur , int x , int n ) { if ( x == 0 ) return int . MaxValue ; if ( x > 0 ) return Math . Abs ( ( n - cur ) / x ) ; else return Math . Abs ( ( cur - 1 ) / x ) ; } static int countSteps ( int curx , int cury , int n , int m , int [ , ] moves ) { int count = 0 ; int k = moves . GetLength ( 0 ) ; for ( int i = 0 ; i < k ; i ++ ) { int x = moves [ i , 0 ] ; int y = moves [ i , 1 ] ; int stepct = Math . Min ( steps ( curx , x , n ) , steps ( cury , y , m ) ) ; count += stepct ; curx += stepct * x ; cury += stepct * y ; } return count ; } public static void Main ( String [ ] args ) { int n = 4 , m = 5 , x = 1 , y = 1 ; int [ , ] moves = { { 1 , 1 } , { 1 , 1 } , { 0 , - 2 } } ; Console . Write ( countSteps ( x , y , n , m , moves ) ) ; } }
Minimum number of elements that should be removed to make the array good | C # implementation of the approach ; Function to return the minimum number of elements that must be removed to make the given array good ; Count frequency of each element ; For each element check if there exists another element that makes a valid pair ; If does not exist then increment answer ; Driver code
using System . Linq ; using System ; class GFG { static int minimumRemoval ( int n , int [ ] a ) { int [ ] c = new int [ 1000 ] ; for ( int i = 0 ; i < n ; i ++ ) c [ a [ i ] ] ++ ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { bool ok = true ; for ( int j = 0 ; j < 31 ; j ++ ) { int x = ( 1 << j ) - a [ i ] ; if ( c . Contains ( x ) && ( c [ x ] > 1 || ( c [ x ] == 1 && x != a [ i ] ) ) ) { ok = false ; break ; } } if ( ! ok ) ans ++ ; } return ans ; } static void Main ( ) { int [ ] a = { 4 , 7 , 1 , 5 , 4 , 9 } ; int n = a . Length ; Console . WriteLine ( minimumRemoval ( n , a ) ) ; } }
Minimum elements to be removed such that sum of adjacent elements is always odd | C # implementation of the above approach ; Returns the minimum number of eliminations ; Stores the previous element ; Stores the new value ; Check if the previous and current values are of same parity ; Previous value is now the current value ; Return the counter variable ; Driver code
using System ; class GFG { static int min_elimination ( int n , int [ ] arr ) { int count = 0 ; int prev_val = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { int curr_val = arr [ i ] ; if ( curr_val % 2 == prev_val % 2 ) count ++ ; prev_val = curr_val ; } return count ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 7 , 9 } ; int n = arr . Length ; Console . WriteLine ( min_elimination ( n , arr ) ) ; } }
Count all possible N digit numbers that satisfy the given condition | C # implementation of above approach ; Function to return the count of required numbers ; If N is odd then return 0 ; Driver Code
using System ; class GFG { static string getCount ( int N ) { if ( N % 2 == 1 ) return "0" ; string result = "9" ; for ( int i = 1 ; i <= N / 2 - 1 ; i ++ ) result += "0" ; return result ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( getCount ( N ) ) ; } }
Maximum number of teams that can be formed with given persons | C # implementation of the approach ; Function that returns true if it possible to form a team with the given n and m ; 1 person of Type1 and 2 persons of Type2 can be chosen ; 1 person of Type2 and 2 persons of Type1 can be chosen ; Cannot from a team ; Function to return the maximum number of teams that can be formed ; To store the required count of teams formed ; Choose 2 persons of Type1 ; And 1 person of Type2 ; Choose 2 persons of Type2 ; And 1 person of Type1 ; Another team has been formed ; Driver code
using System ; class GFG { static bool canFormTeam ( int n , int m ) { if ( n >= 1 && m >= 2 ) return true ; if ( m >= 1 && n >= 2 ) return true ; return false ; } static int maxTeams ( int n , int m ) { int count = 0 ; while ( canFormTeam ( n , m ) ) { if ( n > m ) { n -= 2 ; m -= 1 ; } else { m -= 2 ; n -= 1 ; } count ++ ; } return count ; } public static void Main ( ) { int n = 4 , m = 5 ; Console . WriteLine ( maxTeams ( n , m ) ) ; } }
Find the Side of the smallest Square that can contain given 4 Big Squares | C # program to Find the Side of the smallest Square that can contain given 4 Big Squares Java implementation of the approach ; Function to find the maximum of two values ; Function to find the smallest side of the suitable suitcase ; sort array to find the smallest and largest side of suitcases ; side of the suitcase will be smallest if they arranged in 2 x 2 way so find all possible sides of that arrangement ; since suitcase should be square so find maximum of all four side ; now find greatest side and that will be the smallest square ; return the result ; Driver code ; Get the side of the 4 small squares ; Find the smallest side ; Get the side of the 4 small squares ; Find the smallest side
using System ; class GFG { static long max ( long a , long b ) { if ( a > b ) return a ; else return b ; } static long smallestSide ( long [ ] a ) { Array . Sort ( a ) ; long side1 , side2 , side3 , side4 , side11 , side12 , sideOfSquare ; side1 = a [ 0 ] + a [ 3 ] ; side2 = a [ 1 ] + a [ 2 ] ; side3 = a [ 0 ] + a [ 1 ] ; side4 = a [ 2 ] + a [ 3 ] ; side11 = max ( side1 , side2 ) ; side12 = max ( side3 , side4 ) ; sideOfSquare = max ( side11 , side12 ) ; return sideOfSquare ; } public static void Main ( String [ ] args ) { long [ ] side = new long [ 4 ] ; Console . WriteLine ( " Test ▁ Case ▁ 1" ) ; side [ 0 ] = 2 ; side [ 1 ] = 2 ; side [ 2 ] = 2 ; side [ 3 ] = 2 ; Console . WriteLine ( smallestSide ( side ) ) ; Console . WriteLine ( " STRNEWLINE Test ▁ Case ▁ 2" ) ; side [ 0 ] = 100000000000000L ; side [ 1 ] = 123450000000000L ; side [ 2 ] = 987650000000000L ; side [ 3 ] = 987654321000000L ; Console . WriteLine ( smallestSide ( side ) ) ; } }
Rectangle with minimum possible difference between the length and the width | C # implementation of the approach ; Function to print the length ( l ) and breadth ( b ) of the rectangle having area = N and | l - b | as minimum as possible ; i is a factor ; l >= sqrt ( area ) >= i ; so here l is + ve always ; Here l and b are length and breadth of the rectangle ; Driver code
using System ; class GFG { static void find_rectangle ( int area ) { int l = 0 , b = 0 ; int M = ( int ) Math . Sqrt ( area ) ; for ( int i = M ; i >= 1 ; i -- ) { if ( area % i == 0 ) { l = ( area / i ) ; b = i ; break ; } } Console . WriteLine ( " l ▁ = ▁ " + l + " , ▁ b ▁ = ▁ " + b ) ; } public static void Main ( ) { int area = 99 ; find_rectangle ( area ) ; } }
Rectangle with minimum possible difference between the length and the width | C # implementation of the approach ; Function to print the length ( l ) and breadth ( b ) of the rectangle having area = N and | l - b | as minimum as possible ; Driver code
using System ; class GFG { static void find_rectangle ( int area ) { for ( int i = ( int ) Math . Ceiling ( Math . Sqrt ( area ) ) ; i <= area ; i ++ ) { if ( area / i * i == area ) { Console . WriteLine ( i + " ▁ " + ( int ) ( area / i ) ) ; return ; } } } static void Main ( ) { int area = 99 ; find_rectangle ( area ) ; } }