codeparrot/xlcost-text-to-code huggingface dataset:
Print all Subsequences of String which Start with Vowel and End with Consonant . | C # Program to generate all the subsequence starting with vowel and ending with consonant . ; Set to store all the subsequences ; It computes all the possible substring that starts with vowel and end with consonent ; iterate over the entire string ; test ith character for vowel ; if the ith character is vowel iterate from end of the string and check for consonant . ; test jth character for consonant . ; once we get a consonant add it to the hashset ; drop each character of the substring and recur to generate all subsequence of the substring ; Utility method to check vowel ; Utility method to check consonant ; Driver code
using System ; using System . Collections . Generic ; using System . Text ; class Subsequence { static HashSet < String > st = new HashSet < String > ( ) ; static void subsequence ( String str ) { for ( int i = 0 ; i < str . Length ; i ++ ) { if ( isVowel ( str [ i ] ) ) { for ( int j = ( str . Length - 1 ) ; j >= i ; j -- ) { if ( isConsonant ( str [ j ] ) ) { String str_sub = str . Substring ( i , j - i + 1 ) ; st . Add ( str_sub ) ; for ( int k = 1 ; k < str_sub . Length - 1 ; k ++ ) { StringBuilder sb = new StringBuilder ( str_sub ) ; sb . Remove ( k , 1 ) ; subsequence ( sb . ToString ( ) ) ; } } } } } } static bool isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static bool isConsonant ( char c ) { return ! isVowel ( c ) ; } public static void Main ( String [ ] args ) { String s = " xabcef " ; subsequence ( s ) ; foreach ( String str in st ) Console . Write ( str + " , ▁ " ) ; } }
Null Cipher | A C # program to decode NULL CIPHER ; Function to decode the message . ; Store the decoded string ; found variable is used to tell that the encoded encoded character is found in that particular word . ; Set found variable to false whenever we find whitespace , meaning that encoded character for new word is not found ; Driver Code
using System ; class GFG { static String decode ( String str ) { String res = " " ; Boolean found = false ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == ' ▁ ' ) { found = false ; continue ; } if ( ! found ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { res += ( char ) ( str [ i ] + 32 ) ; found = true ; } else if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) { res += ( char ) str [ i ] ; found = true ; } } } return res ; } public static void Main ( String [ ] args ) { String str ; str = " A ▁ Step ▁ by ▁ Step ▁ Guide ▁ for ▁ Placement ▁ Preparation ▁ by ▁ GeeksforGeeks " ; Console . WriteLine ( " Enciphered ▁ Message : ▁ " + decode ( str ) ) ; } }
Program to count vowels in a string ( Iterative and Recursive ) | Recursive C # program to count the total number of vowels using recursion ; Function to check the Vowel ; to count total number of vowel from 0 to n ; Main Calling Function ; string object ; Total numbers of Vowel
using System ; public class GFG { public static int isVowel ( char ch ) { ch = char . ToUpper ( ch ) ; if ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) { return 1 ; } else { return 0 ; } } public static int countVowels ( string str , int n ) { if ( n == 1 ) { return isVowel ( str [ n - 1 ] ) ; } return countVowels ( str , n - 1 ) + isVowel ( str [ n - 1 ] ) ; } public static void Main ( string [ ] args ) { string str = " abc ▁ de " ; Console . WriteLine ( countVowels ( str , str . Length ) ) ; } }
Generate all rotations of a given string | A simple C # program to generate all rotations of a given string ; Print all the rotated string . ; Concatenate str with itself ; Print all substrings of size n . Note that size of sb is 2 n ; Driver method
using System ; using System . Text ; class Test { static void printRotatedString ( String str ) { int n = str . Length ; StringBuilder sb = new StringBuilder ( str ) ; sb . Append ( str ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j != n ; j ++ ) Console . Write ( sb [ i + j ] ) ; Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { String str = " geeks " ; printRotatedString ( str ) ; } }
Check if frequency of all characters can become same by one removal | C # program to get same frequency character string by removal of at most one char ; Utility method to get index of character ch in lower alphabet characters ; Returns true if all non - zero elements values are same ; get first non - zero element ; check equality of each element with variable same ; Returns true if we can make all character frequencies same ; fill frequency array ; if all frequencies are same , then return true ; Try decreasing frequency of all character by one and then check all equality of all non - zero frequencies ; Check character only if it occurs in str ; Driver code
using System ; class GFG { static int M = 26 ; static int getIdx ( char ch ) { return ( ch - ' a ' ) ; } static bool allSame ( int [ ] freq , int N ) { int same = 0 ; int i ; for ( i = 0 ; i < N ; i ++ ) { if ( freq [ i ] > 0 ) { same = freq [ i ] ; break ; } } for ( int j = i + 1 ; j < N ; j ++ ) if ( freq [ j ] > 0 && freq [ j ] != same ) return false ; return true ; } static bool possibleSameCharFreqByOneRemoval ( string str ) { int l = str . Length ; int [ ] freq = new int [ M ] ; for ( int i = 0 ; i < l ; i ++ ) freq [ getIdx ( str [ i ] ) ] ++ ; if ( allSame ( freq , M ) ) return true ; for ( char c = ' a ' ; c <= ' z ' ; c ++ ) { int i = getIdx ( c ) ; if ( freq [ i ] > 0 ) { freq [ i ] -- ; if ( allSame ( freq , M ) ) return true ; freq [ i ] ++ ; } } return false ; } public static void Main ( ) { string str = " xyyzz " ; if ( possibleSameCharFreqByOneRemoval ( str ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Check if a large number is divisible by 11 or not | C # program to find if a number is divisible by 11 or not ; Function to find that number divisible by 11 or not ; Compute sum of even and odd digit sums ; When i is even , position of digit is odd ; Check its difference is divisible by 11 or not ; main function
using System ; class GFG { static bool check ( string str ) { int n = str . Length ; int oddDigSum = 0 , evenDigSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' ) ; else evenDigSum += ( str [ i ] - '0' ) ; } return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ; } public static void Main ( ) { String str = "76945" ; if ( check ( str ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Hamming Distance between two strings | C # program to find hamming distance b / w two string ; function to calculate Hamming distance ; Driver code ; function call
using System ; class GFG { static int hammingDist ( String str1 , String str2 ) { int i = 0 , count = 0 ; while ( i < str1 . Length ) { if ( str1 [ i ] != str2 [ i ] ) count ++ ; i ++ ; } return count ; } public static void Main ( ) { String str1 = " geekspractice " ; String str2 = " nerdspractise " ; Console . Write ( hammingDist ( str1 , str2 ) ) ; } }
Check if two strings are k | C # program to check if two strings are k anagram or not . ; Function to check that string is k - anagram or not ; If both strings are not of equal length then return false ; Store the occurrence of all characters in a hash_array ; Count number of characters that are different in both strings ; Return true if count is less than or equal to k ; Driver code
using System ; class GFG { static int MAX_CHAR = 26 ; static bool arekAnagrams ( string str1 , string str2 , int k ) { int n = str1 . Length ; if ( str2 . Length != n ) return false ; int [ ] count1 = new int [ MAX_CHAR ] ; int [ ] count2 = new int [ MAX_CHAR ] ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) count1 [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) count2 [ str2 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( count1 [ i ] > count2 [ i ] ) count = count + Math . Abs ( count1 [ i ] - count2 [ i ] ) ; return ( count <= k ) ; } public static void Main ( ) { string str1 = " anagram " ; string str2 = " grammar " ; int k = 2 ; if ( arekAnagrams ( str1 , str2 , k ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Remove spaces from a given string | An efficient C # program to remove all spaces from a string ; Function to remove all spaces from a given string ; To keep track of non - space character count ; Traverse the given string . If current character is not space , then place it at index ' count + + ' ; str [ count ++ ] = str [ i ] ; here count is incremented ; Driver code
using System ; class GFG { static int removeSpaces ( char [ ] str ) { int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) if ( str [ i ] != ' ▁ ' ) return count ; } public static void Main ( String [ ] args ) { char [ ] str = " g ▁ eeks ▁ for ▁ ge ▁ eeks ▁ " . ToCharArray ( ) ; int i = removeSpaces ( str ) ; Console . WriteLine ( String . Join ( " " , str ) . Substring ( 0 , i ) ) ; } }
Given a binary string , count number of substrings that start and end with 1. | A O ( n ) C # program to count number of substrings starting and ending with 1 ; Traverse input string and count of 1 's in it ; Return count of possible pairs among m 1 's ; Driver Code
using System ; class GFG { int countSubStr ( char [ ] str , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '1' ) m ++ ; } return m * ( m - 1 ) / 2 ; } public static void Main ( String [ ] args ) { GFG count = new GFG ( ) ; String strings = "00100101" ; char [ ] str = strings . ToCharArray ( ) ; int n = str . Length ; Console . Write ( count . countSubStr ( str , n ) ) ; } }
Given a number as a string , find the number of contiguous subsequences which recursively add up to 9 | C # program to count substrings with recursive sum equal to 9 ; To store result ; Consider every character as beginning of substring ; sum of digits in current substring ; One by one choose every character as an ending character ; Add current digit to sum , if sum becomes multiple of 5 then increment count . Let us do modular arithmetic to avoid overflow for big strings ; Driver Code
using System ; class GFG { static int count9s ( String number ) { int count = 0 ; int n = number . Length ; for ( int i = 0 ; i < n ; i ++ ) { int sum = number [ i ] - '0' ; if ( number [ i ] == '9' ) count ++ ; for ( int j = i + 1 ; j < n ; j ++ ) { sum = ( sum + number [ j ] - '0' ) % 9 ; if ( sum == 0 ) count ++ ; } } return count ; } public static void Main ( ) { Console . WriteLine ( count9s ( "4189" ) ) ; Console . WriteLine ( count9s ( "1809" ) ) ; } }
Generate n | C # program to generate n - bit Gray codes ; This function generates all n bit Gray codes and prints the generated codes ; base case ; ' arr ' will store all generated codes ; start with one - bit pattern ; Every iteration of this loop generates 2 * i codes from previously generated i codes . ; Enter the prviously generated codes again in arr [ ] in reverse order . Nor arr [ ] has double number of codes . ; append 0 to the first half ; append 1 to the second half ; print contents of arr [ ] ; Driver program to test above function
using System ; using System . Collections . Generic ; public class GfG { public static void generateGrayarr ( int n ) { if ( n <= 0 ) { return ; } List < string > arr = new List < string > ( ) ; arr . Add ( "0" ) ; arr . Add ( "1" ) ; int i , j ; for ( i = 2 ; i < ( 1 << n ) ; i = i << 1 ) { for ( j = i - 1 ; j >= 0 ; j -- ) { arr . Add ( arr [ j ] ) ; } for ( j = 0 ; j < i ; j ++ ) { arr [ j ] = "0" + arr [ j ] ; } for ( j = i ; j < 2 * i ; j ++ ) { arr [ j ] = "1" + arr [ j ] ; } } for ( i = 0 ; i < arr . Count ; i ++ ) { Console . WriteLine ( arr [ i ] ) ; } } public static void Main ( string [ ] args ) { generateGrayarr ( 3 ) ; } }
Rat in a Maze Problem when movement in all possible directions is allowed | C # implementation of the above approach ; List to store all the possible paths ; Function returns true if the move taken is valid else it will return false . ; Function to print all the possible paths from ( 0 , 0 ) to ( n - 1 , n - 1 ) . ; This will check the initial point ( i . e . ( 0 , 0 ) ) to start the paths . ; If reach the last cell ( n - 1 , n - 1 ) then store the path and return ; Mark the cell as visited ; Check if downward move is valid ; Check if the left move is valid ; Check if the right move is valid ; Check if the upper move is valid ; Mark the cell as unvisited for other possible paths ; Function to store and print all the valid paths ; Call the utility function to find the valid paths ; Print all possible paths ; Driver code
using System ; using System . Collections . Generic ; class GFG { static List < String > possiblePaths = new List < String > ( ) ; static String path = " " ; static readonly int MAX = 5 ; static bool isSafe ( int row , int col , int [ , ] m , int n , bool [ , ] visited ) { if ( row == - 1 row == n col == - 1 col == visited [ row , col ] m [ row , col ] == 0 ) return false ; return true ; } static void printPathUtil ( int row , int col , int [ , ] m , int n , bool [ , ] visited ) { if ( row == - 1 row == n col == - 1 col == visited [ row , col ] m [ row , col ] == 0 ) return ; if ( row == n - 1 && col == n - 1 ) { possiblePaths . Add ( path ) ; return ; } visited [ row , col ] = true ; if ( isSafe ( row + 1 , col , m , n , visited ) ) { path += ' D ' ; printPathUtil ( row + 1 , col , m , n , visited ) ; path = path . Substring ( 0 , path . Length - 1 ) ; } if ( isSafe ( row , col - 1 , m , n , visited ) ) { path += ' L ' ; printPathUtil ( row , col - 1 , m , n , visited ) ; path = path . Substring ( 0 , path . Length - 1 ) ; } if ( isSafe ( row , col + 1 , m , n , visited ) ) { path += ' R ' ; printPathUtil ( row , col + 1 , m , n , visited ) ; path = path . Substring ( 0 , path . Length - 1 ) ; } if ( isSafe ( row - 1 , col , m , n , visited ) ) { path += ' U ' ; printPathUtil ( row - 1 , col , m , n , visited ) ; path = path . Substring ( 0 , path . Length - 1 ) ; } visited [ row , col ] = false ; } static void printPath ( int [ , ] m , int n ) { bool [ , ] visited = new bool [ n , MAX ] ; printPathUtil ( 0 , 0 , m , n , visited ) ; for ( int i = 0 ; i < possiblePaths . Count ; i ++ ) Console . Write ( possiblePaths [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ , ] m = { { 1 , 0 , 0 , 0 , 0 } , { 1 , 1 , 1 , 1 , 1 } , { 1 , 1 , 1 , 0 , 1 } , { 0 , 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 0 , 1 } } ; int n = m . GetLength ( 0 ) ; printPath ( m , n ) ; } }
N Queen in O ( n ) space | C # code to for n Queen placement ; Function to check queens placement ; Helper Function to check if queen can be placed ; Function to display placed queen ; Driver Code
using System ; class GfG { static void breakLine ( ) { Console . Write ( " -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - " } static int = 10 ; static int [ ] arr = new int [ MAX ] ; static int no ; static void nQueens ( int k , int n ) { for ( int i = 1 ; i <= n ; i ++ ) { if ( canPlace ( k , i ) ) { arr [ k ] = i ; if ( k == n ) { display ( n ) ; } else { nQueens ( k + 1 , n ) ; } } } } static bool canPlace ( int k , int i ) { for ( int j = 1 ; j <= k - 1 ; j ++ ) { if ( arr [ j ] == i || ( Math . Abs ( arr [ j ] - i ) == Math . Abs ( j - k ) ) ) { return false ; } } return true ; } static void display ( int n ) { breakLine ( ) ; Console . Write ( " Arrangement ▁ No . ▁ " + ++ no ) ; breakLine ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( arr [ i ] != j ) { Console . Write ( " TABSYMBOL _ " ) ; } else { Console . Write ( " TABSYMBOL Q " ) ; } } Console . WriteLine ( " " ) ; } breakLine ( ) ; } public static void Main ( String [ ] args ) { int n = 4 ; nQueens ( 1 , n ) ; } }
Numbers that are bitwise AND of at least one non | C # implementation of the approach ; Set to store all possible AND values . ; Starting index of the sub - array . ; Ending index of the sub - array . ; AND value is added to the set . ; displaying the values
using System ; using System . Collections . Generic ; class CP { public static void Main ( String [ ] args ) { int [ ] A = { 11 , 15 , 7 , 19 } ; int N = A . Length ; HashSet < int > set1 = new HashSet < int > ( ) ; int i , j , res ; for ( i = 0 ; i < N ; ++ i ) { for ( j = i , res = int . MaxValue ; j < N ; ++ j ) { res &= A [ j ] ; set1 . Add ( res ) ; } } foreach ( int m in set1 ) { Console . Write ( m + " ▁ " ) ; } } }
Collect all coins in minimum number of steps | C # Code to Collect all coins in minimum number of steps ; recursive method to collect coins from height array l to r , with height h already collected ; if l is more than r , no steps needed ; loop over heights to get minimum height index ; choose minimum from , 1 ) collecting coins using all vertical lines ( total r - l ) 2 ) collecting coins using lower horizontal lines and recursively on left and right segments ; method returns minimum number of step to collect coin from stack , with height in height [ ] array ; Driver program to test above function
using System ; class GFG { public static int minStepsRecur ( int [ ] height , int l , int r , int h ) { if ( l >= r ) return 0 ; int m = l ; for ( int i = l ; i < r ; i ++ ) if ( height [ i ] < height [ m ] ) m = i ; return Math . Min ( r - l , minStepsRecur ( height , l , m , height [ m ] ) + minStepsRecur ( height , m + 1 , r , height [ m ] ) + height [ m ] - h ) ; } public static int minSteps ( int [ ] height , int N ) { return minStepsRecur ( height , 0 , N , 0 ) ; } public static void Main ( ) { int [ ] height = { 2 , 1 , 2 , 5 , 1 } ; int N = height . Length ; Console . Write ( minSteps ( height , N ) ) ; } }
Count of Unique Direct Path Between N Points On a Plane | C # program for the above approach ; Function to count the total number of direct paths ; Driver Code
using System ; public class GFG { static int countDirectPath ( int N ) { return N + ( N * ( N - 3 ) ) / 2 ; } public static void Main ( string [ ] args ) { int N = 5 ; Console . Write ( countDirectPath ( N ) ) ; } }
Triacontagon Number | C # program for above approach ; Finding the nth triacontagonal number ; Driver code
using System ; class GFG { static int triacontagonalNum ( int n ) { return ( 28 * n * n - 26 * n ) / 2 ; } public static void Main ( ) { int n = 3 ; Console . Write ( "3rd ▁ triacontagonal ▁ Number ▁ is ▁ = ▁ " + triacontagonalNum ( n ) ) ; } }
Hexacontagon Number | C # program for above approach ; Finding the nth hexacontagon number ; Driver code
using System ; class GFG { public static int hexacontagonNum ( int n ) { return ( 58 * n * n - 56 * n ) / 2 ; } public static void Main ( ) { int n = 3 ; Console . Write ( "3rd ▁ hexacontagon ▁ Number ▁ is ▁ = ▁ " + hexacontagonNum ( n ) ) ; } }
Enneacontagon Number | C # program for above approach ; Finding the nth enneacontagon number ; Driver code
using System ; class GFG { public static int enneacontagonNum ( int n ) { return ( 88 * n * n - 86 * n ) / 2 ; } public static void Main ( String [ ] args ) { int n = 3 ; Console . WriteLine ( "3rd ▁ enneacontagon ▁ Number ▁ is ▁ = ▁ " + enneacontagonNum ( n ) ) ; } }
Triacontakaidigon Number | C # program for above approach ; Finding the nth triacontakaidigon number ; Driver code
using System ; class GFG { public static int triacontakaidigonNum ( int n ) { return ( 30 * n * n - 28 * n ) / 2 ; } public static void Main ( String [ ] args ) { int n = 3 ; Console . WriteLine ( "3rd ▁ triacontakaidigon ▁ Number ▁ is ▁ = ▁ " + triacontakaidigonNum ( n ) ) ; } }
Icosihexagonal Number | C # program for above approach ; Finding the nth icosihexagonal number ; Driver code
using System ; class GFG { public static int IcosihexagonalNum ( int n ) { return ( 24 * n * n - 22 * n ) / 2 ; } public static void Main ( String [ ] args ) { int n = 3 ; Console . WriteLine ( "3rd ▁ Icosihexagonal ▁ Number ▁ is ▁ = ▁ " + IcosihexagonalNum ( n ) ) ; } }
Icosikaioctagon or Icosioctagon Number | C # program for above approach ; Finding the nth icosikaioctagonal number ; Driver code
using System ; class GFG { public static int icosikaioctagonalNum ( int n ) { return ( 26 * n * n - 24 * n ) / 2 ; } public static void Main ( ) { int n = 3 ; Console . Write ( "3rd ▁ icosikaioctagonal ▁ Number ▁ is ▁ = ▁ " + icosikaioctagonalNum ( n ) ) ; } }
Octacontagon Number | C # program for above approach ; Finding the nth octacontagon Number ; Driver Code
using System ; class GFG { static int octacontagonNum ( int n ) { return ( 78 * n * n - 76 * n ) / 2 ; } public static void Main ( ) { int n = 3 ; Console . Write ( "3rd ▁ octacontagon ▁ Number ▁ is ▁ = ▁ " + octacontagonNum ( n ) ) ; } }
Hectagon Number | C # program for above approach ; Finding the nth hectagon Number ; Driver Code
using System ; class GFG { static int hectagonNum ( int n ) { return ( 98 * n * n - 96 * n ) / 2 ; } public static void Main ( ) { int n = 3 ; Console . Write ( "3rd ▁ hectagon ▁ Number ▁ is ▁ = ▁ " + hectagonNum ( n ) ) ; } }
Tetracontagon Number | C # program for above approach ; Finding the nth tetracontagon number ; Driver code
using System ; class GFG { static int tetracontagonNum ( int n ) { return ( 38 * n * n - 36 * n ) / 2 ; } public static void Main ( string [ ] args ) { int n = 3 ; Console . Write ( "3rd ▁ tetracontagon ▁ Number ▁ is ▁ = ▁ " + tetracontagonNum ( n ) ) ; } }
Perimeter of an Ellipse | C # program to find perimeter of an Ellipse . ; Function to find perimeter of an ellipse . ; formula to find the Perimeter of an Ellipse . ; Display the result ; Driver code
using System ; class GFG1 { static void Perimeter ( double a , double b ) { double Perimeter ; Perimeter = ( double ) 2 * 3.14 * Math . Sqrt ( ( a * a + b * b ) / ( 2 * 1.0 ) ) ; Console . WriteLine ( " Perimeter : ▁ " + Perimeter ) ; } public static void Main ( String [ ] args ) { double a = 3 , b = 2 ; Perimeter ( a , b ) ; } }
Biggest Reuleaux Triangle within A Square | C # program to find area of the biggest Reuleaux triangle that can be inscribed within a square ; Function to find the area of the reuleaux triangle ; Side cannot be negative ; Area of the reauleaux triangle ; Driver code
using System ; class GFG { static double reuleauxArea ( double a ) { if ( a < 0 ) return - 1 ; double A = 0.70477 * Math . Pow ( a , 2 ) ; return A ; } static public void Main ( ) { double a = 6 ; Console . WriteLine ( reuleauxArea ( a ) ) ; } }
Largest hexagon that can be inscribed within a square | C # Program to find the biggest hexagon which can be inscribed within the given square ; Function to return the side of the hexagon ; Side cannot be negative ; Side of the hexagon ; Driver code
using System ; class GFG { static double hexagonside ( double a ) { if ( a < 0 ) return - 1 ; double x = ( 0.5176 * a ) ; return x ; } public static void Main ( ) { double a = 6 ; Console . WriteLine ( hexagonside ( a ) ) ; } }
Largest hexagon that can be inscribed within an equilateral triangle | C # program to find the side of the largest hexagon which can be inscribed within an equilateral triangle ; Function to find the side of the hexagon ; Side cannot be negative ; Side of the hexagon ; Driver code
using System ; class CLG { static float hexagonside ( float a ) { if ( a < 0 ) return - 1 ; float x = a / 3 ; return x ; } public static void Main ( ) { float a = 6 ; Console . Write ( hexagonside ( a ) ) ; } }
Find middle point segment from given segment lengths | C # implementation of the approach ; Function that returns the segment for the middle point ; the middle point ; stores the segment index ; increment sum by length of the segment ; if the middle is in between two segments ; if sum is greater than middle point ; Driver code
using System ; class GFG { static int findSegment ( int n , int m , int [ ] segment_length ) { double meet_point = ( 1.0 * n ) / 2.0 ; int sum = 0 ; int segment_number = 0 ; for ( int i = 0 ; i < m ; i ++ ) { sum += segment_length [ i ] ; if ( ( double ) sum == meet_point ) { segment_number = - 1 ; break ; } if ( sum > meet_point ) { segment_number = i + 1 ; break ; } } return segment_number ; } public static void Main ( ) { int n = 13 ; int m = 3 ; int [ ] segment_length = new int [ ] { 3 , 2 , 8 } ; int ans = findSegment ( n , m , segment_length ) ; Console . WriteLine ( ans ) ; } }