codeparrot/xlcost-text-to-code huggingface dataset:
Nth Even length Palindrome | C # program to find nth even length Palindrome ; Function to find nth even length Palindrome ; string r to store resultant palindrome . Initialize same as s ; In this loop string r stores reverse of string s after the string s in consecutive manner ; Driver code ; Function call
using System ; class GFG { static string evenlength ( string n ) { string res = n ; for ( int j = n . Length - 1 ; j >= 0 ; -- j ) res += n [ j ] ; return res ; } public static void Main ( ) { string n = "10" ; Console . WriteLine ( evenlength ( n ) ) ; } }
Program to count occurrence of a given character in a string | package whatever do not write package name here ; base case ; ; checking if the first character of the given string is that character or not ; this will count the occurrence of given character in the string from index 1 to the last index of the string ; Driver code
using System ; public class GFG { static int countinString ( char ch , String s ) { if ( s . Length == 0 ) return 0 ; int count = 0 ; if ( s [ 0 ] == ch ) count ++ ; count += countinString ( ch , s . Substring ( 1 ) ) ; return count ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; char c = ' e ' ; Console . WriteLine ( countinString ( c , str ) ) ; } }
Determine if a string has all Unique Characters | C # program to illustrate string with unique characters using brute force technique ; If at any time we encounter 2 same characters , return false ; If no duplicate characters encountered , return true ; Driver Code
using System ; public class GFG { static bool uniqueCharacters ( String str ) { for ( int i = 0 ; i < str . Length ; i ++ ) for ( int j = i + 1 ; j < str . Length ; j ++ ) if ( str [ i ] == str [ j ] ) return false ; return true ; } public static void Main ( ) { string input = " GeeksforGeeks " ; if ( uniqueCharacters ( input ) == true ) Console . WriteLine ( " The ▁ String ▁ " + input + " ▁ has ▁ all ▁ unique ▁ characters " ) ; else Console . WriteLine ( " The ▁ String ▁ " + input + " ▁ has ▁ duplicate ▁ characters " ) ; } }
Check if given string can be split into four distinct strings | C # program to check if we can break a string into four distinct strings . ; Return true if both strings are equal ; Return if the given string can be split or not . ; Brute Force ; Making 4 string from the given string ; Checking if they are distinct or not . ; Driver code
using System ; class GFG { public static Boolean strcheck ( String s1 , String s2 ) { if ( s1 . CompareTo ( s2 ) != 0 ) return false ; return true ; } public static Boolean check ( String s ) { if ( s . Length >= 10 ) return true ; for ( int i = 1 ; i < s . Length ; i ++ ) { for ( int j = i + 1 ; j < s . Length ; j ++ ) { for ( int k = j + 1 ; k < s . Length ; k ++ ) { String s1 = " " , s2 = " " , s3 = " " , s4 = " " ; try { s1 = s . Substring ( 0 , i ) ; s2 = s . Substring ( i , j - i ) ; s3 = s . Substring ( j , k - j ) ; s4 = s . Substring ( k , s . Length - k ) ; } catch ( Exception e ) { } if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ; } } } return false ; } public static void Main ( String [ ] args ) { String str = " aaabb " ; if ( check ( str ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Multiply Large Numbers represented as Strings | C # program to multiply two numbers represented as Strings . ; Multiplies str1 and str2 , and prints result . ; will keep the result number in vector in reverse order ; Below two indexes are used to find positions in result . ; Go from right to left in num1 ; To shift position to left after every multipliccharAtion of a digit in num2 ; Go from right to left in num2 ; Take current digit of second number ; Multiply with current digit of first number and add result to previously stored result charAt current position . ; Carry for next itercharAtion ; Store result ; store carry in next cell ; To shift position to left after every multipliccharAtion of a digit in num1 . ; ignore '0' s from the right ; If all were '0' s - means either both or one of num1 or num2 were '0' ; genercharAte the result String ; Driver code
using System ; class GFG { static String multiply ( String num1 , String num2 ) { int len1 = num1 . Length ; int len2 = num2 . Length ; if ( len1 == 0 len2 == 0 ) return "0" ; int [ ] result = new int [ len1 + len2 ] ; int i_n1 = 0 ; int i_n2 = 0 ; int i ; for ( i = len1 - 1 ; i >= 0 ; i -- ) { int carry = 0 ; int n1 = num1 [ i ] - '0' ; i_n2 = 0 ; for ( int j = len2 - 1 ; j >= 0 ; j -- ) { int n2 = num2 [ j ] - '0' ; int sum = n1 * n2 + result [ i_n1 + i_n2 ] + carry ; carry = sum / 10 ; result [ i_n1 + i_n2 ] = sum % 10 ; i_n2 ++ ; } if ( carry > 0 ) result [ i_n1 + i_n2 ] += carry ; i_n1 ++ ; } i = result . Length - 1 ; while ( i >= 0 && result [ i ] == 0 ) i -- ; if ( i == - 1 ) return "0" ; String s = " " ; while ( i >= 0 ) s += ( result [ i -- ] ) ; return s ; } public static void Main ( String [ ] args ) { String str1 = "1235421415454545454545454544" ; String str2 = "1714546546546545454544548544544545" ; if ( ( str1 [ 0 ] == ' - ' str2 [ 0 ] == ' - ' ) && ( str1 [ 0 ] != ' - ' str2 [ 0 ] != ' - ' ) ) Console . Write ( " - " ) ; if ( str1 [ 0 ] == ' - ' && str2 [ 0 ] != ' - ' ) { str1 = str1 . Substring ( 1 ) ; } else if ( str1 [ 0 ] != ' - ' && str2 [ 0 ] == ' - ' ) { str2 = str2 . Substring ( 1 ) ; } else if ( str1 [ 0 ] == ' - ' && str2 [ 0 ] == ' - ' ) { str1 = str1 . Substring ( 1 ) ; str2 = str2 . Substring ( 1 ) ; } Console . WriteLine ( multiply ( str1 , str2 ) ) ; } }
Find an equal point in a string of brackets | C # program to find an index k which decides the number of opening brackets is equal to the number of closing brackets ; Method to find an equal index ; Store the number of opening brackets at each index ; Store the number of closing brackets at each index ; check if there is no opening or closing brackets ; check if there is any index at which both brackets are equal ; Driver Code
using System ; class GFG { static int findIndex ( string str ) { int len = str . Length ; int [ ] open = new int [ len + 1 ] ; int [ ] close = new int [ len + 1 ] ; int index = - 1 ; open [ 0 ] = 0 ; close [ len ] = 0 ; if ( str [ 0 ] == ' ( ' ) open [ 1 ] = 1 ; if ( str [ len - 1 ] == ' ) ' ) close [ len - 1 ] = 1 ; for ( int i = 1 ; i < len ; i ++ ) { if ( str [ i ] == ' ( ' ) open [ i + 1 ] = open [ i ] + 1 ; else open [ i + 1 ] = open [ i ] ; } for ( int i = len - 2 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ) ' ) close [ i ] = close [ i + 1 ] + 1 ; else close [ i ] = close [ i + 1 ] ; } if ( open [ len ] == 0 ) return len ; if ( close [ 0 ] == 0 ) return 0 ; for ( int i = 0 ; i <= len ; i ++ ) if ( open [ i ] == close [ i ] ) index = i ; return index ; } public static void Main ( ) { string str = " ( ( ) ) ) ( ( ) ( ) ( ) ) ) ) " ; Console . Write ( findIndex ( str ) ) ; } }
Convert decimal fraction to binary number | C # program to convert fractional decimal to binary number ; Function to convert decimal to binary upto k - precision after decimal point ; Fetch the integral part of decimal number ; Fetch the fractional part decimal number ; Conversion of integral part to binary equivalent ; Append 0 in binary ; Reverse string to get original binary equivalent ; Append point before conversion of fractional part ; Conversion of fractional part to binary equivalent ; Find next bit in fraction ; Swap values of left and right ; Driver code
using System ; class GFG { static String decimalToBinary ( double num , int k_prec ) { String binary = " " ; int Integral = ( int ) num ; double fractional = num - Integral ; while ( Integral > 0 ) { int rem = Integral % 2 ; binary += ( ( char ) ( rem + '0' ) ) ; Integral /= 2 ; } binary = reverse ( binary ) ; binary += ( ' . ' ) ; while ( k_prec -- > 0 ) { fractional *= 2 ; int fract_bit = ( int ) fractional ; if ( fract_bit == 1 ) { fractional -= fract_bit ; binary += ( char ) ( 1 + '0' ) ; } else { binary += ( char ) ( 0 + '0' ) ; } } return binary ; } static String reverse ( String input ) { char [ ] temparray = input . ToCharArray ( ) ; int left , right = 0 ; right = temparray . Length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { char temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return String . Join ( " " , temparray ) ; } public static void Main ( String [ ] args ) { double n = 4.47 ; int k = 3 ; Console . WriteLine ( decimalToBinary ( n , k ) ) ; n = 6.986 ; k = 5 ; Console . WriteLine ( decimalToBinary ( n , k ) ) ; } }
Difference of two large numbers | C # program to find difference of two large numbers . ; Returns true if str1 is smaller than str2 , else false . ; Calculate lengths of both string ; Function for finding difference of larger numbers ; Before proceeding further , make sure str1 is not smaller ; Take an empty string for storing result ; Calculate lengths of both string ; Initially take carry zero ; Traverse from end of both strings ; Do school mathematics , compute difference of current digits and carry ; subtract remaining digits of str1 [ ] ; if ( i > 0 sub > 0 ) remove preceding 0 's ; reverse resultant string ; Driver code ; Function call
using System ; class GFG { static bool isSmaller ( string str1 , string str2 ) { int n1 = str1 . Length , n2 = str2 . Length ; if ( n1 < n2 ) return true ; if ( n2 < n1 ) return false ; for ( int i = 0 ; i < n1 ; i ++ ) { if ( str1 [ i ] < str2 [ i ] ) return true ; else if ( str1 [ i ] > str2 [ i ] ) return false ; } return false ; } static string findDiff ( string str1 , string str2 ) { if ( isSmaller ( str1 , str2 ) ) { string t = str1 ; str1 = str2 ; str2 = t ; } String str = " " ; int n1 = str1 . Length , n2 = str2 . Length ; int diff = n1 - n2 ; int carry = 0 ; for ( int i = n2 - 1 ; i >= 0 ; i -- ) { int sub = ( ( ( int ) str1 [ i + diff ] - ( int ) '0' ) - ( ( int ) str2 [ i ] - ( int ) '0' ) - carry ) ; if ( sub < 0 ) { sub = sub + 10 ; carry = 1 ; } else carry = 0 ; str += sub . ToString ( ) ; } for ( int i = n1 - n2 - 1 ; i >= 0 ; i -- ) { if ( str1 [ i ] == '0' && carry > 0 ) { str += "9" ; continue ; } int sub = ( ( ( int ) str1 [ i ] - ( int ) '0' ) - carry ) ; str += sub . ToString ( ) ; carry = 0 ; } char [ ] aa = str . ToCharArray ( ) ; Array . Reverse ( aa ) ; return new string ( aa ) ; } public static void Main ( ) { String str1 = "88" ; String str2 = "1079" ; Console . WriteLine ( findDiff ( str1 , str2 ) ) ; } }
Efficiently check if a string has all unique characters without using any additional data structure | Driver code
using System ; public class GFG { static bool unique ( String s ) { Array . Sort ( s . ToCharArray ( ) ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) { return false ; } } return true ; } public static void Main ( String [ ] args ) { if ( unique ( " abcdd " ) == true ) { Console . WriteLine ( " String ▁ is ▁ Unique " ) ; } else { Console . WriteLine ( " String ▁ is ▁ not ▁ Unique " ) ; } } }
Check if two strings are k | Optimized C # program to check if two strings are k anagram or not . ; Function to check if str1 and str2 are k - anagram or not ; If both strings are not of equal [ i ] then return false ; Store the occurrence of all characters in a hash_array ; Store the occurrence of all characters in a hash_array ; 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 [ ] hash_str1 = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) hash_str1 [ str1 [ i ] - ' a ' ] ++ ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( hash_str1 [ str2 [ i ] - ' a ' ] > 0 ) hash_str1 [ str2 [ i ] - ' a ' ] -- ; else count ++ ; if ( count > k ) return false ; } return true ; } static void Main ( ) { String str1 = " fodr " ; String str2 = " gork " ; int k = 2 ; if ( areKAnagrams ( str1 , str2 , k ) == true ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Nth character in Concatenated Decimal String | C # program to get Nth character in concatenated Decimal String ; Utility method to get dth digit of number N ; Method to return Nth character in concatenated decimal string ; sum will store character escaped till now ; dist will store numbers escaped till now ; loop for number lengths ; nine * len will be incremented characters and nine will be incremented numbers ; restore variables to previous correct state ; get distance from last one digit less maximum number ; d will store dth digit of current number ; method will return dth numbered digit of ( dist + diff ) number ; Driver code
using System ; class GFG { static char getDigit ( int N , int d ) { string str = Convert . ToString ( N ) ; return str [ d - 1 ] ; } static char getNthChar ( int N ) { int sum = 0 , nine = 9 ; int dist = 0 , len ; for ( len = 1 ; ; len ++ ) { sum += nine * len ; dist += nine ; if ( sum >= N ) { sum -= nine * len ; dist -= nine ; N -= sum ; break ; } nine *= 10 ; } int diff = ( int ) ( Math . Ceiling ( ( double ) ( N ) / ( double ) ( len ) ) ) ; int d = N % len ; if ( d == 0 ) d = len ; return getDigit ( dist + diff , d ) ; } static void Main ( ) { int N = 251 ; Console . WriteLine ( getNthChar ( N ) ) ; } }
Minimum characters to be added at front to make string palindrome | C # program for getting minimum character to be added at front to make string palindrome ; function for checking string is palindrome or not ; Driver code ; if string becomes palindrome then break ; erase the last element of the string ; print the number of insertion at front
using System ; public class GFG { static bool ispalindrome ( String s ) { int l = s . Length ; for ( int i = 0 , j = l - 1 ; i <= j ; i ++ , j -- ) { if ( s [ i ] != s [ j ] ) { return false ; } } return true ; } public static void Main ( ) { String s = " BABABAA " ; int cnt = 0 ; int flag = 0 ; while ( s . Length > 0 ) { if ( ispalindrome ( s ) ) { flag = 1 ; break ; } else { cnt ++ ; s = s . Substring ( 0 , s . Length - 1 ) ; s . erase ( s . begin ( ) + s . length ( ) - 1 ) ; } } if ( flag == 1 ) { Console . WriteLine ( cnt ) ; } } }
Count characters at same position as in English alphabet | C # program to find number of characters at same position as in English alphabets ; Traverse input string ; Check that index of characters of string is same as of English alphabets by using ASCII values and the fact that all lower case alphabetic characters come together in same order in ASCII table . And same is true for upper case . ; Driver code
using System ; class GFG { static int findCount ( string str ) { int result = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) if ( i == ( str [ i ] - ' a ' ) || i == ( str [ i ] - ' A ' ) ) result ++ ; return result ; } public static void Main ( ) { string str = " AbgdeF " ; Console . Write ( findCount ( str ) ) ; } }
Remove a character from a string to make it a palindrome | C # program to check whether it is possible to make string palindrome by removing one character ; Utility method to check if substring from low to high is palindrome or not . ; This method returns - 1 if it is not possible to make string a palindrome . It returns - 2 if string is already a palindrome . Otherwise it returns index of character whose removal can make the whole string palindrome . ; Initialize low and right by both the ends of the string ; loop until low and high cross each other ; If both characters are equal then move both pointer towards end ; * If removing str [ low ] makes the * whole string palindrome . We basically * check if substring str [ low + 1. . high ] * is palindrome or not . ; * If removing str [ high ] makes the whole string * palindrome . We basically check if substring * str [ low + 1. . high ] is palindrome or not . ; We reach here when complete string will be palindrome if complete string is palindrome then return mid character ; Driver Code
using System ; class GFG { static bool isPalindrome ( string str , int low , int high ) { while ( low < high ) { if ( str [ low ] != str [ high ] ) return false ; low ++ ; high -- ; } return true ; } static int possiblePalinByRemovingOneChar ( string str ) { int low = 0 , high = str . Length - 1 ; while ( low < high ) { if ( str [ low ] == str [ high ] ) { low ++ ; high -- ; } else { if ( isPalindrome ( str , low + 1 , high ) ) return low ; if ( isPalindrome ( str , low , high - 1 ) ) return high ; return - 1 ; } } return - 2 ; } public static void Main ( String [ ] args ) { string str = " abecbea " ; int idx = possiblePalinByRemovingOneChar ( str ) ; if ( idx == - 1 ) Console . Write ( " Not ▁ Possible " ) ; else if ( idx == - 2 ) Console . Write ( " Possible ▁ without ▁ " + " removing ▁ any ▁ character " ) ; else Console . Write ( " Possible ▁ by ▁ removing " + " ▁ character ▁ at ▁ index ▁ " + idx ) ; } }
Print all words matching a pattern in CamelCase Notation Dictionary | C # program to print all words in the CamelCase dictionary that matches with a given pattern ; Alphabet size ( # of upper - Case characters ) ; A Trie node ; isLeaf is true if the node represents end of a word ; vector to store list of complete words in leaf node ; Function to insert word into the Trie ; consider only uppercase characters ; get current character position ; mark last node as leaf ; push word into vector associated with leaf node ; Function to print all children of Trie node root ; if current node is leaf ; recurse for all children of root node ; search for pattern in Trie and print all words matching that pattern ; Invalid pattern ; print all words matching that pattern ; Main function to print all words in the CamelCase dictionary that matches with a given pattern ; construct Trie root node ; Construct Trie from given dict ; search for pattern in Trie ; Driver Code ; dictionary of words where each word follows CamelCase notation ; pattern consisting of uppercase characters only
using System ; using System . Collections . Generic ; class GFG { static int ALPHABET_SIZE = 26 ; public class TrieNode { public TrieNode [ ] children = new TrieNode [ ALPHABET_SIZE ] ; public bool isLeaf ; public List < String > word ; public TrieNode ( ) { isLeaf = false ; for ( int i = 0 ; i < ALPHABET_SIZE ; i ++ ) children [ i ] = null ; word = new List < String > ( ) ; } } static TrieNode root ; static void insert ( String word ) { int index ; TrieNode pCrawl = root ; for ( int level = 0 ; level < word . Length ; level ++ ) { if ( char . IsLower ( word [ level ] ) ) continue ; index = word [ level ] - ' A ' ; if ( pCrawl . children [ index ] == null ) pCrawl . children [ index ] = new TrieNode ( ) ; pCrawl = pCrawl . children [ index ] ; } pCrawl . isLeaf = true ; ( pCrawl . word ) . Add ( word ) ; } static void printAllWords ( TrieNode root ) { if ( root . isLeaf ) { foreach ( String str in root . word ) Console . WriteLine ( str ) ; } for ( int i = 0 ; i < ALPHABET_SIZE ; i ++ ) { TrieNode child = root . children [ i ] ; if ( child != null ) printAllWords ( child ) ; } } static bool search ( String pattern ) { int index ; TrieNode pCrawl = root ; for ( int level = 0 ; level < pattern . Length ; level ++ ) { index = pattern [ level ] - ' A ' ; if ( pCrawl . children [ index ] == null ) return false ; pCrawl = pCrawl . children [ index ] ; } printAllWords ( pCrawl ) ; return true ; } static void findAllWords ( List < String > dict , String pattern ) { root = new TrieNode ( ) ; foreach ( String word in dict ) insert ( word ) ; if ( ! search ( pattern ) ) Console . WriteLine ( " No ▁ match ▁ found " ) ; } public static void Main ( String [ ] args ) { List < String > dict = new List < String > { " Hi " , " Hello " , " HelloWorld " , " HiTech " , " HiGeek " , " HiTechWorld " , " HiTechCity " , " HiTechLab " } ; String pattern = " HT " ; findAllWords ( dict , pattern ) ; } }
Generate all binary strings from given pattern | Recursive C # program to generate all binary strings formed by replacing each wildcard character by 0 or 1 ; Recursive function to generate all binary strings formed by replacing each wildcard character by 0 or 1 ; replace ' ? ' by '0' and recurse ; replace ' ? ' by '1' and recurse ; NOTE : Need to backtrack as string is passed by reference to the function ; Driver Code
using System ; class GFG { public static void print ( char [ ] str , int index ) { if ( index == str . Length ) { Console . WriteLine ( str ) ; return ; } if ( str [ index ] == ' ? ' ) { str [ index ] = '0' ; print ( str , index + 1 ) ; str [ index ] = '1' ; print ( str , index + 1 ) ; str [ index ] = ' ? ' ; } else print ( str , index + 1 ) ; } public static void Main ( ) { string input = "1 ? ? 0?101" ; char [ ] str = input . ToCharArray ( ) ; print ( str , 0 ) ; } }
Find the most frequent digit without using array / string | Finds maximum occurring digit without using any array / string ; Simple function to count occurrences of digit d in x ; Initialize count of digit d ; Increment count if current digit is same as d ; Returns the max occurring digit in x ; Handle negative number ; Initialize result which is a digit ; Initialize count of result ; Traverse through all digits ; Count occurrences of current digit ; Update max_count and result if needed ; Driver Code
class GFG { static int countOccurrences ( int x , int d ) { int count = 0 ; while ( x > 0 ) { if ( x % 10 == d ) count ++ ; x = x / 10 ; } return count ; } static int maxOccurring ( int x ) { if ( x < 0 ) x = - x ; int result = 0 ; int max_count = 1 ; for ( int d = 0 ; d <= 9 ; d ++ ) { int count = countOccurrences ( x , d ) ; if ( count >= max_count ) { max_count = count ; result = d ; } } return result ; } static void Main ( ) { int x = 1223355 ; System . Console . WriteLine ( " Max ▁ occurring ▁ digit ▁ is ▁ " + maxOccurring ( x ) ) ; } }
Remove recurring digits in a given number | C # program to remove recurring digits from a given number ; Removes recurring digits in num [ ] ; int j = 0 ; Index in modified string ; Traverse digits of given number one by one ; Copy the first occurrence of new digit ; Remove repeating occurrences of digit ; Driver code
using System ; class GFG { static String removeRecurringDigits ( char [ ] num ) { int len = num . Length ; String s = " " ; for ( int i = 0 ; i < len ; i ++ ) { s += String . Join ( " " , num [ i ] ) ; while ( i + 1 < len && num [ i ] == num [ i + 1 ] ) { i ++ ; } } return s ; } public static void Main ( ) { char [ ] num = "1299888833" . ToCharArray ( ) ; Console . Write ( " Modified ▁ number ▁ is ▁ " + removeRecurringDigits ( num ) ) ; } }
Find the maximum subarray XOR in a given array | A simple C # program to find max subarray XOR ; Pick starting points of subarrays ; to store xor of current subarray ; Pick ending points of subarrays starting with i ; Driver code
using System ; class GFG { static int maxSubarrayXOR ( int [ ] arr , int n ) { int ans = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) { int curr_xor = 0 ; for ( int j = i ; j < n ; j ++ ) { curr_xor = curr_xor ^ arr [ j ] ; ans = Math . Max ( ans , curr_xor ) ; } } return ans ; } public static void Main ( ) { int [ ] arr = { 8 , 1 , 2 , 12 } ; int n = arr . Length ; Console . WriteLine ( " Max ▁ subarray ▁ XOR ▁ is ▁ " + maxSubarrayXOR ( arr , n ) ) ; } }
Recursive Implementation of atoi ( ) | Recursive C # program to compute atoi ( ) ; Recursive function to compute atoi ( ) ; Base case ( Only one digit ) ; If more than 1 digits , recur for ( n - 1 ) , multiplu result with 10 and add last digit ; Driver code
using System ; class GFG { static int myAtoiRecursive ( string str , int n ) { if ( n == 1 ) { return str [ 0 ] - '0' ; } return ( 10 * myAtoiRecursive ( str , n - 1 ) + str [ n - 1 ] - '0' ) ; } public static void Main ( ) { string str = "112" ; int n = str . Length ; Console . Write ( myAtoiRecursive ( str , n ) ) ; } }