codeparrot/xlcost-text-to-code huggingface dataset:
Maximize count of pairs whose bitwise XOR is even by replacing such pairs with their Bitwise XOR | C # program to implement the above approach ; Function to maximize the count of pairs with even XOR possible in an array by given operations ; Stores count of odd array elements ; Traverse the array ; If arr [ i ] is odd ; Stores the total number of even pairs ; Driver Code ; Input ; Function call to count the number of pairs whose XOR is even
using System ; class GFG { static int countPairs ( int [ ] arr , int N ) { int odd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; } int ans = ( N - odd + odd / 2 - 1 ) + odd / 2 ; return ans ; } public static void Main ( ) { int [ ] arr = { 4 , 6 , 1 , 3 } ; int N = arr . Length ; Console . Write ( countPairs ( arr , N ) ) ; } }
Maximize count of pairs whose Bitwise AND exceeds Bitwise XOR by replacing such pairs with their Bitwise AND | C # program for the above approach ; Function to count the number of pairs whose Bitwise AND is greater than the Bitwise XOR ; Stores the frequency of MSB of array elements ; Traverse the array ; Increment count of numbers having MSB at log ( arr [ i ] ) ; Stores total number of pairs ; Traverse the Map ; Return total count of pairs ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int countPairs ( int [ ] arr , int N ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( freq . ContainsKey ( ( int ) ( Math . Log ( Convert . ToDouble ( arr [ i ] ) , 2.0 ) ) ) ) freq [ ( int ) ( Math . Log ( Convert . ToDouble ( arr [ i ] ) , 2.0 ) ) ] ++ ; else freq [ ( int ) ( Math . Log ( Convert . ToDouble ( arr [ i ] ) , 2.0 ) ) ] = 1 ; } int pairs = 0 ; foreach ( var item in freq ) { pairs += item . Value - 1 ; } return pairs ; } public static void Main ( ) { int [ ] arr = { 12 , 9 , 15 , 7 } ; int N = arr . Length ; Console . WriteLine ( countPairs ( arr , N ) ) ; } }
Maximize difference between odd and even indexed array elements by swapping unequal adjacent bits in their binary representations | C # program for the above approach ; Function to count total number of bits present in a number ; Function to count total set bits in a number ; Stores the count of set bits ; Right shift by 1 ; Return the final count ; Function to find maximum number by shifting two unequal bits ; Count set bits in number n ; Iterate the string bits ; Function to find minimum number by shifting two unequal bits ; Iterate the set bit ; Function to find the maximum difference ; Stores the maximum difference ; Stores the sum of elements placed at odd positions ; Stores the sum of elements placed at even positions ; Traverse the array ; Update CaseOne ; Stores the maximum difference ; Assign value O ; Traverse the array ; Update caseTwo ; Return maximum of caseOne and CaseTwo ; Driver Code ; Function Call
using System ; class GFG { static int countBit ( int n ) { return ( int ) ( ( Math . Log ( n ) / Math . Log ( 2 ) ) + 1 ) ; } static int countSetBit ( int n ) { int ans = 0 ; while ( n > 0 ) { ans += ( n & 1 ) ; n >>= 1 ; } return ans ; } static int maximize ( int n ) { int bits = countBit ( n ) ; int setBits = countSetBit ( n ) ; int ans = 0 ; for ( int i = 0 ; i < bits ; i ++ ) { if ( i < setBits ) ans |= 1 ; if ( i != setBits - 1 ) ans <<= 1 ; } return ans ; } static int minimize ( int n ) { int setBits = countSetBit ( n ) ; int ans = 0 ; for ( int i = 0 ; i < setBits ; i ++ ) { ans |= 1 ; if ( i != setBits - 1 ) ans <<= 1 ; } return ans ; } static int maxDiff ( int [ ] arr ) { int caseOne = 0 ; int SumOfOdd = 0 ; int SumOfeven = 0 ; for ( int i = 0 ; i < arr . Length ; i ++ ) { if ( ( i % 2 ) != 0 ) SumOfOdd += minimize ( arr [ i ] ) ; else SumOfeven += maximize ( arr [ i ] ) ; } caseOne = Math . Abs ( SumOfOdd - SumOfeven ) ; int caseTwo = 0 ; SumOfOdd = 0 ; SumOfeven = 0 ; for ( int i = 0 ; i < arr . Length ; i ++ ) { if ( ( i % 2 ) != 0 ) SumOfOdd += maximize ( arr [ i ] ) ; else SumOfeven += minimize ( arr [ i ] ) ; } caseTwo = Math . Abs ( SumOfOdd - SumOfeven ) ; return Math . Max ( caseOne , caseTwo ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 54 , 32 , 11 , 23 } ; Console . Write ( maxDiff ( arr ) ) ; } }
Sum of numbers obtained by the count of set and non | C # program for the above approach ; Functino to find the number after processing the diagonal elements ; Store the required number ; Checking for each position ; Store the number of set bits & non - set bits at position i ; Traverse the diagonal elements ; Update count of S if current element is set at position i ; Else update NS ; If number of set bits is > number of non - set bits , add set bits value to the ans ; Return the answer ; Function to find the sum of the numbers generated after processing both the diagonals of the matrix ; Store the primary diagonal elements ; Store the secondary diagonal elements ; Function Call to get the required numbers and return their sum ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int processDiagonal ( List < int > arr ) { int ans = 0 ; int getBit = 1 ; for ( int i = 0 ; i < 32 ; i ++ ) { int S = 0 ; int NS = 0 ; foreach ( int j in arr ) { if ( ( getBit & j ) != 0 ) S += 1 ; else NS += 1 ; } if ( S > NS ) ans += ( int ) Math . Pow ( 2 , i ) ; getBit <<= 1 ; } return ans ; } static int findSum ( int [ , ] mat ) { int i = 0 ; int j = 0 ; List < int > priDiag = new List < int > ( ) ; while ( i < mat . GetLength ( 0 ) ) { priDiag . Add ( mat [ i , j ] ) ; i += 1 ; j += 1 ; } i = 0 ; j = mat . GetLength ( 0 ) - 1 ; List < int > secDiag = new List < int > ( ) ; while ( i < mat . GetLength ( 0 ) ) { secDiag . Add ( mat [ i , j ] ) ; i += 1 ; j -= 1 ; } return ( processDiagonal ( priDiag ) + processDiagonal ( secDiag ) ) ; } public static void Main ( string [ ] args ) { int [ , ] mat = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; Console . Write ( findSum ( mat ) ) ; } }
Minimize difference between two sequences obtained by splitting first N powers of 2 | C # program for the above approach ; Function to partition first N powers of 2 into two subsequences with minimum difference between their sum ; Largest element in the first part ; Place N / 2 - 1 smallest elements in the first sequence ; Place remaining N / 2 elements in the second sequence ; Print the minimum difference ; Driver Code
using System ; class GFG { static void minimumDifference ( int N ) { int sum1 = ( 1 << N ) , sum2 = 0 ; for ( int i = 1 ; i < N / 2 ; i ++ ) sum1 += ( 1 << i ) ; for ( int i = N / 2 ; i < N ; i ++ ) sum2 += ( 1 << i ) ; Console . WriteLine ( sum1 - sum2 ) ; } static public void Main ( ) { int N = 4 ; minimumDifference ( N ) ; } }
Check whether N can be a Perfect Cube after adding or subtracting K | C # implementation of the above approach ; Function to check if a number is a perfect Cube or not ; Driver code
using System ; class GFG { static bool isPerfectCube ( int x ) { int cr = ( int ) Math . Cbrt ( x ) ; return ( cr * cr * cr == x ) ; } static void canBePerfectCube ( int N , int K ) { if ( isPerfectCube ( N + K ) || isPerfectCube ( N - K ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( string [ ] args ) { int N = 7 ; int K = 1 ; canBePerfectCube ( N , K ) ; N = 5 ; K = 4 ; canBePerfectCube ( N , K ) ; N = 7 ; K = 2 ; canBePerfectCube ( N , K ) ; } }
Floor square root without using sqrt ( ) function : Recursive | C # implementation to find the square root of the number N without using sqrt ( ) function ; Function to find the square root of the number N using BS ; If the range is still valid ; Find the mid - value of the range ; Base Case ; Condition to check if the left search space is useless ; Driver Code
using System ; class GFG { static int sqrtSearch ( int low , int high , int N ) { if ( low <= high ) { int mid = ( int ) ( low + high ) / 2 ; if ( ( mid * mid <= N ) && ( ( mid + 1 ) * ( mid + 1 ) > N ) ) { return mid ; } else if ( mid * mid < N ) { return sqrtSearch ( mid + 1 , high , N ) ; } else { return sqrtSearch ( low , mid - 1 , N ) ; } } return low ; } public static void Main ( String [ ] args ) { int N = 25 ; Console . WriteLine ( sqrtSearch ( 0 , N , N ) ) ; } }
Common divisors of N numbers | C # program to find all common divisors of N numbers ; Function to calculate gcd of two numbers ; Function to print all the common divisors ; Variable to find the gcd of N numbers ; Set to store all the common divisors ; Finding GCD of the given N numbers ; Finding divisors of the HCF of n numbers ; Print all the divisors ; Driver 's Code ; Function to print all the common divisors
using System ; using System . Collections . Generic ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static void printAllDivisors ( int [ ] arr , int N ) { int g = arr [ 0 ] ; HashSet < int > divisors = new HashSet < int > ( ) ; for ( int i = 1 ; i < N ; i ++ ) { g = gcd ( arr [ i ] , g ) ; } for ( int i = 1 ; i * i <= g ; i ++ ) { if ( g % i == 0 ) { divisors . Add ( i ) ; if ( g / i != i ) divisors . Add ( g / i ) ; } } foreach ( int it in divisors ) Console . Write ( it + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 6 , 90 , 12 , 18 , 30 , 24 } ; int n = arr . Length ; printAllDivisors ( arr , n ) ; } }
Recursive Program to print multiplication table of a number | C # program to print table of a number using recursion ; Function that print the table of a given number using recursion ; Base Case ; Print the table for current iteration ; Recursive call to next iteration ; Driver Code ; Input number whose table is to print ; Function call to print the table
using System ; class GFG { static void mul_table ( int N , int i ) { if ( i > 10 ) return ; Console . WriteLine ( N + " ▁ * ▁ " + i + " ▁ = ▁ " + N * i ) ; mul_table ( N , i + 1 ) ; } public static void Main ( ) { int N = 8 ; mul_table ( N , 1 ) ; } }
Find the largest composite number that divides N but is strictly lesser than N | C # program to find the largest composite number that divides N which is less than N ; Function to check whether a number is prime or not ; Corner case ; Check from 2 to n - 1 ; Function that find the largest composite number which divides N and less than N ; Find the prime number ; Driver Code ; Get the smallest prime factor ; Check if ( N / a ) is prime or not . If Yes print " - 1" ; Else print largest composite number ( N / a )
using System ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static int getSmallestPrimefactor ( int n ) { for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return i ; } return - 1 ; } public static void Main ( ) { int N = 100 ; int a ; a = getSmallestPrimefactor ( N ) ; if ( isPrime ( N / a ) ) { Console . Write ( " - 1" ) ; } else { Console . Write ( N / a ) ; } } }
Check if N and M can be made equal by increasing N by A and decreasing M by B | C # program to check if two numbers can be made equal by increasing the first by a and decreasing the second by b ; Function to whether the numbers can be made equal or not ; Check whether the numbers can reach an equal point or not ; M and N cannot be made equal by increasing M and decreasing N when M is already greater than N ; Driver code
using System ; class GFG { static bool checkEqualNo ( int m , int n , int a , int b ) { if ( m <= n ) { if ( ( n - m ) % ( a + b ) == 0 ) { return true ; } else { return false ; } } else { return false ; } } public static void Main ( String [ ] args ) { int M = 2 ; int N = 8 ; int A = 3 ; int B = 3 ; if ( checkEqualNo ( M , N , A , B ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
XOR and OR of all N | C # program to find the XOR and OR of all palindrome numbers of N digits ; Function to check if a number is palindrome or not ; Convert the num n to string ; Iterate over string to check whether it is palindromic or not ; Function to find XOR of all N - digits palindrome number ; To store the XOR and OR of all palindromic number ; Starting N - digit palindromic number ; Ending N - digit palindromic number ; Iterate over starting and / ending number ; To check if i is palindromic or not ; Print the XOR and OR of all palindromic number ; Driver Code
using System ; class GFG { static bool ispalin ( int num ) { string s = num . ToString ( ) ; int st = 0 ; int ed = s . Length - 1 ; while ( st <= ed ) { if ( s [ st ] != s [ ed ] ) return false ; st ++ ; ed -- ; } return true ; } static void CalculateXORandOR ( int n ) { int CalculateXOR = 0 ; int CalculateOR = 0 ; int start = ( int ) Math . Pow ( 10 , n - 1 ) ; int end = ( int ) Math . Pow ( 10 , n ) - 1 ; for ( int i = start ; i <= end ; i ++ ) { if ( ispalin ( i ) ) { CalculateXOR = CalculateXOR ^ i ; CalculateOR = CalculateOR | i ; } } Console . Write ( " XOR ▁ = ▁ " + CalculateXOR ) ; Console . WriteLine ( " ▁ OR ▁ = ▁ " + CalculateOR ) ; } public static void Main ( string [ ] args ) { int n = 4 ; CalculateXORandOR ( n ) ; } }
Sum of all palindromic numbers lying in the range [ L , R ] for Q queries | C # program to find the sum of all palindrome numbers in the given range ; pref [ ] array to precompute the sum of all palindromic number ; Function that return number num if num is palindromic else return 0 ; Convert num to String ; Function to precompute the sum of all palindrome numbers upto 100000 ; checkPalindrome ( ) return the number i if i is palindromic else return 0 ; Function to print the sum for each query ; Function to print sum of all palindromic numbers between [ L , R ] ; Function that pre computes the sum of all palindromic numbers ; Iterate over all Queries to print the sum ; Driver code ; Queries ; Function that print the the sum of all palindromic number in Range [ L , R ]
using System ; class GFG { static int [ ] pref = new int [ 100001 ] ; static int checkPalindrome ( int num ) { String str = String . Join ( " " , num ) ; int l = 0 , r = str . Length - 1 ; while ( l < r ) { if ( str [ l ] != str [ r ] ) { return 0 ; } l ++ ; r -- ; } return num ; } static void preCompute ( ) { for ( int i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + checkPalindrome ( i ) ; } } static void printSum ( int L , int R ) { Console . Write ( pref [ R ] - pref [ L - 1 ] + " STRNEWLINE " ) ; } static void printSumPalindromic ( int [ , ] arr , int Q ) { preCompute ( ) ; for ( int i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i , 0 ] , arr [ i , 1 ] ) ; } } public static void Main ( String [ ] args ) { int Q = 2 ; int [ , ] arr = { { 10 , 13 } , { 12 , 21 } } ; printSumPalindromic ( arr , Q ) ; } }
Sum of alternating sign Squares of first N natural numbers | C # program to find Sum of alternating sign Squares of first N natural numbers ; Function to calculate the alternating sign sum ; Variable to store the sum ; Loop to iterate each number from 1 to N ; The alternating sign is put by checking if the number is even or odd ; Add the square with the sign ; Add the square with the sign ; Driver code
using System ; class GFG { static int summation ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 1 ) sum += ( i * i ) ; else sum -= ( i * i ) ; } return sum ; } public static void Main ( ) { int N = 2 ; Console . WriteLine ( summation ( N ) ) ; } }
Sum of alternating sign Squares of first N natural numbers | C # program to find Sum of alternating sign Squares of first N natural numbers ; Function to calculate the alternating sign sum ; Variable to store the absolute sum ; Variable to store the sign ; Variable to store the resultant sum ; Driver code
using System ; public class GFG { static int summation ( int n ) { int abs_sum = ( int ) ( n * ( n + 1 ) / 2 ) ; int sign = n + 1 % 2 == 0 ? 1 : - 1 ; int result_sum = sign * abs_sum ; return result_sum ; } public static void Main ( ) { int N = 2 ; Console . WriteLine ( summation ( N ) ) ; } }
Count pairs from 1 to N such that their Sum is divisible by their XOR | C # program to count pairs from 1 to N such that their Sum is divisible by their XOR ; Function to count pairs ; variable to store count ; Generate all possible pairs such that 1 <= x < y < n ; Driver code
using System ; public class GFG { static int countPairs ( int n ) { int count = 0 ; for ( int x = 1 ; x < n ; x ++ ) { for ( int y = x + 1 ; y <= n ; y ++ ) { if ( ( y + x ) % ( y ^ x ) == 0 ) count ++ ; } } return count ; } public static void Main ( ) { int n = 6 ; Console . WriteLine ( countPairs ( n ) ) ; } }
Count pairs in array such that one element is power of another | C # program to count pairs in array such that one element is power of another ; Function to check if given number number y is power of x ; log function to calculate value ; compare to the result1 or result2 both are equal ; Function to find pairs from array ; Iterate through all pairs ; Increment count if one is the power of other ; Driver code
using System ; public class GFG { static bool isPower ( int x , int y ) { int res1 = ( int ) ( Math . Log ( y ) / Math . Log ( x ) ) ; double res2 = Math . Log ( y ) / Math . Log ( x ) ; return ( res1 == res2 ) ; } static int countPower ( int [ ] arr , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( isPower ( arr [ i ] , arr [ j ] ) || isPower ( arr [ j ] , arr [ i ] ) ) res ++ ; return res ; } public static void Main ( ) { int [ ] a = { 16 , 2 , 3 , 9 } ; int n = a . Length ; Console . WriteLine ( countPower ( a , n ) ) ; } }
Find the original Array using XOR values of all adjacent elements | C # implementation to find the Array from the XOR array of the adjacent elements of array ; XOR of all elements from 1 to N ; Function to find the Array from the XOR Array ; Take a vector to store the permutation ; XOR of N natural numbers ; Loop to find the XOR of adjacent elements of the XOR Array ; Loop to find the other elements of the permutation ; Finding the next and next elements ; Driver Code ; Required Permutation
using System ; using System . Collections . Generic ; class GFG { static int xor_all_elements ( int n ) { switch ( n & 3 ) { case 0 : return n ; case 1 : return 1 ; case 2 : return n + 1 ; } return 0 ; } static List < int > findArray ( int [ ] xorr , int n ) { List < int > arr = new List < int > ( ) ; int xor_all = xor_all_elements ( n ) ; int xor_adjacent = 0 ; for ( int i = 0 ; i < n - 1 ; i += 2 ) { xor_adjacent = xor_adjacent ^ xorr [ i ] ; } int last_element = xor_all ^ xor_adjacent ; arr . Add ( last_element ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { last_element = xorr [ i ] ^ last_element ; arr . Add ( last_element ) ; } return arr ; } public static void Main ( String [ ] args ) { List < int > arr = new List < int > ( ) ; int [ ] xorr = { 7 , 5 , 3 , 7 } ; int n = 5 ; arr = findArray ( xorr , n ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } }
Sum of non | C # implementation of the above approach ; Function to return a vector which consists the sum of four portions of the matrix ; Iterating through the matrix ; Condition for selecting all values before the second diagonal of metrics ; Top portion of the matrix ; Left portion of the matrix ; Bottom portion of the matrix ; Right portion of the matrix ; Adding all the four portions into a vector ; Driver code
using System ; class GFG { static int sumOfParts ( int [ , ] arr , int N ) { int sum_part1 = 0 , sum_part2 = 0 , sum_part3 = 0 , sum_part4 = 0 ; int totalsum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i + j < N - 1 ) { if ( i < j && i != j && i + j > 0 ) sum_part1 += arr [ i , j ] ; else if ( i != j ) sum_part2 += arr [ i , j ] ; } else { if ( i > j && i + j != N - 1 ) sum_part3 += arr [ i , j ] ; else { if ( i + j != N - 1 && i != j ) sum_part4 += arr [ i , j ] ; } } } } totalsum = sum_part1 + sum_part2 + sum_part3 + sum_part4 ; return totalsum ; } public static void Main ( ) { int N = 4 ; int [ , ] arr = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; Console . WriteLine ( sumOfParts ( arr , N ) ) ; } }
Check if X and Y can be made zero by using given operation any number of times | C # implementation of the approach ; Function to check if X and Y can be made equal to zero by using given operation any number of times ; Check for the two conditions ; Driver code
using System ; class GFG { static void ifPossible ( int X , int Y ) { if ( X > Y ) swap ( X , Y ) ; if ( ( X + Y ) % 5 == 0 && 3 * X >= 2 * Y ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } static void swap ( int x , int y ) { int temp = x ; x = y ; y = temp ; } public static void Main ( ) { int X = 33 , Y = 27 ; ifPossible ( X , Y ) ; } }
Largest Even and Odd N | C # implementation of the approach ; Function to print the largest n - digit even and odd numbers in hexadecimal number system ; Append ' F ' ( N - 1 ) times ; Append ' E ' for an even number ; Append ' F ' for an odd number ; Driver code
using System ; class GFG { static void findNumbers ( int n ) { String ans = strings ( n - 1 , ' F ' ) ; String even = ans + ' E ' ; String odd = ans + ' F ' ; Console . Write ( " Even : ▁ " + even + " STRNEWLINE " ) ; Console . Write ( " Odd : ▁ " + odd + " STRNEWLINE " ) ; } private static String strings ( int n , char c ) { String str = " " ; for ( int i = 0 ; i < n ; i ++ ) str += c ; return str ; } public static void Main ( String [ ] args ) { int n = 2 ; findNumbers ( n ) ; } }
Program to compute log a to any base b ( logb a ) | C # program to find log ( a ) on any base b ; Driver code
using System ; public class GFG { static int log_a_to_base_b ( int a , int b ) { return ( int ) ( Math . Log ( a ) / Math . Log ( b ) ) ; } public static void Main ( ) { int a = 3 ; int b = 2 ; Console . WriteLine ( log_a_to_base_b ( a , b ) ) ; a = 256 ; b = 4 ; Console . WriteLine ( log_a_to_base_b ( a , b ) ) ; } }
Program to compute log a to any base b ( logb a ) | C # program to find log ( a ) on any base b using Recursion ; Recursive function to compute log a to the base b ; Driver code
using System ; class GFG { static int log_a_to_base_b ( int a , int b ) { int rslt = ( a > b - 1 ) ? 1 + log_a_to_base_b ( a / b , b ) : 0 ; return rslt ; } public static void Main ( ) { int a = 3 ; int b = 2 ; Console . WriteLine ( log_a_to_base_b ( a , b ) ) ; a = 256 ; b = 4 ; Console . WriteLine ( log_a_to_base_b ( a , b ) ) ; } }
Largest and Smallest N | C # program to find the largest and smallest N - digit numbers in Hexa - Decimal Number System ; Function to return the largest N - digit number in Hexa - Decimal Number System ; Append ' F ' N times ; Function to return the smallest N - digit number in Hexa - Decimal Number System ; Append '0' ( N - 1 ) times to 1 ; Function to print the largest and smallest N - digit Hexa - Decimal number ; Driver code
using System ; class GFG { static string findLargest ( int N ) { string largest = " " ; for ( int i = 0 ; i < N ; i ++ ) largest += ' F ' ; return largest ; } static string findSmallest ( int N ) { string smallest = "1" ; for ( int i = 0 ; i < N - 1 ; i ++ ) smallest += '0' ; return smallest ; } static void print ( int largest ) { Console . WriteLine ( " Largest : ▁ " + findLargest ( largest ) ) ; Console . WriteLine ( " Smallest : ▁ " + findSmallest ( largest ) ) ; } public static void Main ( string [ ] args ) { int N = 4 ; print ( N ) ; } }
Highest and Smallest power of K less than and greater than equal to N respectively | C # implementation of the approach ; Function to return the highest power of k less than or equal to n ; Function to return the smallest power of k greater than or equal to n ; Function to print the result ; Driver Code
using System ; class GFG { static int prevPowerofK ( int n , int k ) { int p = ( int ) ( Math . Log ( n ) / Math . Log ( k ) ) ; return ( int ) Math . Pow ( k , p ) ; } static int nextPowerOfK ( int n , int k ) { return prevPowerofK ( n , k ) * k ; } static void printResult ( int n , int k ) { Console . WriteLine ( prevPowerofK ( n , k ) + " ▁ " + nextPowerOfK ( n , k ) ) ; } public static void Main ( String [ ] args ) { int n = 25 , k = 3 ; printResult ( n , k ) ; } }