codeparrot/xlcost-text-to-code huggingface dataset:
Check if all elements of the given array can be made 0 by decrementing value in pairs | C # program to make the array zero by decrementing value in pairs ; Function to check if all the elements can be made 0 in an array ; Variable to store sum and maximum element in an array ; Loop to calculate the sum and max value of the given array ; If n is 1 or sum is odd or sum - max element < max then no solution ; For the remaining case , print Yes ; Driver code
using System ; class GFG { static void canMake ( int n , int [ ] ar ) { int sum = 0 , maxx = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { sum += ar [ i ] ; maxx = Math . Max ( maxx , ar [ i ] ) ; } if ( n == 1 sum % 2 == 1 sum - maxx < maxx ) { Console . Write ( " No STRNEWLINE " ) ; } else { Console . Write ( " Yes STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int n = 6 ; int [ ] arr = { 1 , 1 , 2 , 3 , 6 , 11 } ; canMake ( n , arr ) ; } }
Sum of all Perfect Squares lying in the range [ L , R ] for Q queries | C # program to find the sum of all perfect squares in the given range ; Array to precompute the sum of squares from 1 to 100010 so that for every query , the answer can be returned in O ( 1 ) . ; Function to check if a number is a perfect square or not ; Find floating point value of square root of x . ; If square root is an integer ; Function to precompute the perfect squares upto 100000. ; Function to print the sum for each query ; Driver code ; To calculate the precompute function ; Calling the printSum function for every query
using System ; class GFG { static int [ ] pref = new int [ 100010 ] ; static int isPerfectSquare ( int x ) { double sr = Math . Sqrt ( x ) ; return ( ( sr - Math . Floor ( sr ) ) == 0 ) ? x : 0 ; } static void compute ( ) { for ( int i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfectSquare ( i ) ; } } static void printSum ( int L , int R ) { int sum = pref [ R ] - pref [ L - 1 ] ; Console . Write ( sum + " ▁ " ) ; } public static void Main ( String [ ] args ) { compute ( ) ; int Q = 4 ; int [ , ] arr = { { 1 , 10 } , { 1 , 100 } , { 2 , 25 } , { 4 , 50 } } ; for ( int i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i , 0 ] , arr [ i , 1 ] ) ; } } }
Program to find all Factors of a Number using recursion | C # program to find all the factors of a number using recursion ; Recursive function to print factors of a number ; Checking if the number is less than N ; Calling the function recursively for the next number ; Driver code
using System ; class GFG { static void factors ( int n , int i ) { if ( i <= n ) { if ( n % i == 0 ) { Console . WriteLine ( i + " ▁ " ) ; } factors ( n , i + 1 ) ; } } public static void Main ( ) { int n = 16 ; factors ( n , 1 ) ; } }
Maximize value of ( a + b ) such that ( a * a | C # program to maximize the value of ( a + b ) such that ( a * a - b * b = N ) ; Function to maximize the value of ( a + b ) such that ( a * a - b * b = n ) ; Driver code
using System ; class GFG { static int maxValue ( int n ) { return n ; } public static void Main ( String [ ] args ) { int n = 1 ; Console . Write ( maxValue ( n ) ) ; } }
Maximum number of edges that N | C # implementation to find the maximum number of edges for triangle free graph ; Function to find the maximum number of edges in a N - vertex graph . ; According to the Mantel 's theorem  the maximum number of edges will be  floor of [(n^2)/4] ; Driver code
using System ; class GFG { public static int solve ( int n ) { int ans = ( n * n / 4 ) ; return ans ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( solve ( n ) ) ; } }
Multiplication table till N rows where every Kth row is table of K upto Kth term | C # program to print multiplication table till N rows where every Kth row is the table of K up to Kth term ; Function to print the multiplication table upto K - th term ; For loop to iterate from 1 to N where i serves as the value of K ; Inner loop which at every iteration goes till i ; Printing the table value for i ; New line after every row ; Driver code
using System ; class GFG { public static void printMultiples ( int N ) { for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { Console . Write ( ( i * j ) + " ▁ " ) ; } Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { int N = 5 ; printMultiples ( N ) ; } }
Boundary Value Analysis : Nature of Roots of a Quadratic equation | C # program to check the nature of the roots ; BVA for nature of roots of a quadratic equation ; If a = 0 , D / 2 a will yield exception Hence it is not a valid Quadratic Equation ; If D > 0 , it will be Real Roots ; If D == 0 , it will be Equal Roots ; If D < 0 , it will be Imaginary Roots ; Function to check for all testcases ; Driver Code
using System ; class GFG { static void nature_of_roots ( int a , int b , int c ) { if ( a == 0 ) { Console . Write ( " Not ▁ a ▁ Quadratic ▁ Equation " + " STRNEWLINE " ) ; return ; } int D = b * b - 4 * a * c ; if ( D > 0 ) { Console . Write ( " Real ▁ Roots " + " STRNEWLINE " ) ; } else if ( D == 0 ) { Console . Write ( " Equal ▁ Roots " + " STRNEWLINE " ) ; } else { Console . Write ( " Imaginary ▁ Roots " + " STRNEWLINE " ) ; } } static void checkForAllTestCase ( ) { Console . Write ( " Testcase " + " TABSYMBOL a TABSYMBOL b TABSYMBOL c TABSYMBOL Actual ▁ Output " + " STRNEWLINE " ) ; Console . WriteLine ( ) ; int a , b , c ; a = b = c = 0 ; int testcase = 1 ; while ( testcase <= 13 ) { if ( testcase == 1 ) { a = 0 ; b = 50 ; c = 50 ; } else if ( testcase == 2 ) { a = 1 ; b = 50 ; c = 50 ; } else if ( testcase == 3 ) { a = 50 ; b = 50 ; c = 50 ; } else if ( testcase == 4 ) { a = 99 ; b = 50 ; c = 50 ; } else if ( testcase == 5 ) { a = 100 ; b = 50 ; c = 50 ; } else if ( testcase == 6 ) { a = 50 ; b = 0 ; c = 50 ; } else if ( testcase == 7 ) { a = 50 ; b = 1 ; c = 50 ; } else if ( testcase == 8 ) { a = 50 ; b = 99 ; c = 50 ; } else if ( testcase == 9 ) { a = 50 ; b = 100 ; c = 50 ; } else if ( testcase == 10 ) { a = 50 ; b = 50 ; c = 0 ; } else if ( testcase == 11 ) { a = 50 ; b = 50 ; c = 1 ; } else if ( testcase == 12 ) { a = 50 ; b = 50 ; c = 99 ; } else if ( testcase == 13 ) { a = 50 ; b = 50 ; c = 100 ; } Console . Write ( " TABSYMBOL " + testcase + " TABSYMBOL " + a + " TABSYMBOL " + b + " TABSYMBOL " + c + " TABSYMBOL " ) ; nature_of_roots ( a , b , c ) ; Console . WriteLine ( ) ; testcase ++ ; } } public static void Main ( String [ ] args ) { checkForAllTestCase ( ) ; } }
Find if the Vacation can be taken or not | C # program to find if the Vacation can be taken or not ; Function to find if the Vacation is possible or not ; Find the required number of hours of study ; find the hours of study that can be done if the vacation is taken ; check if the required hours are less than or equal to the hours of study that can be done if the vacation is taken ; Driver Code
using System ; class GFG { static int isPossible ( int N , int S , int C , int H , int L , int T ) { int total_time_required = S * C * H ; int available_time_after_vacation = ( N - L ) * T ; if ( available_time_after_vacation >= total_time_required ) return 1 ; return 0 ; } public static void Main ( String [ ] args ) { int N = 12 , S = 5 , C = 8 , H = 3 , L = 2 , T = 20 ; if ( isPossible ( N , S , C , H , L , T ) == 1 ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else Console . Write ( " No " + " STRNEWLINE " ) ; N = 1 ; S = 2 ; C = 3 ; H = 4 ; L = 5 ; T = 6 ; if ( isPossible ( N , S , C , H , L , T ) == 1 ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else Console . Write ( " No " + " STRNEWLINE " ) ; } }
Find Maximum and Minimum of two numbers using Absolute function | C # program to find maximum and minimum using Absolute function ; Function to return maximum among the two numbers ; Function to return minimum among the two numbers ; Driver code ; Displaying the maximum value ; Displaying the minimum value
using System ; class GFG { static int maximum ( int x , int y ) { return ( ( x + y + Math . Abs ( x - y ) ) / 2 ) ; } static int minimum ( int x , int y ) { return ( ( x + y - Math . Abs ( x - y ) ) / 2 ) ; } public static void Main ( ) { int x = 99 , y = 18 ; Console . WriteLine ( " Maximum : ▁ " + maximum ( x , y ) ) ; Console . WriteLine ( " Minimum : ▁ " + minimum ( x , y ) ) ; } }
Find an array of size N having exactly K subarrays with sum S | C # program to find array with K subarrays with sum S ; Function to find array with K subarrays with sum S ; Driver Code ; Function call
using System ; class GFG { static void SubarraysWithSumS ( int n , int k , int s ) { for ( int i = 0 ; i < k ; i ++ ) Console . Write ( s + " ▁ " ) ; for ( int i = k ; i < n ; i ++ ) Console . Write ( s + 1 + " ▁ " ) ; } public static void Main ( String [ ] args ) { int n = 4 , k = 2 , s = 3 ; SubarraysWithSumS ( n , k , s ) ; } }
Minimum number of cuts required to pay salary from N length Gold Bar | C # Implementation to find the minimum number of cuts to pay the worker . ; Function to find the minimum number of cuts to pay the worker . ; Nearest int to the Log value of the number N ; Driver code ; Cuts Required in the Length of 15
using System ; class GFG { static int pay ( int n ) { int cuts = ( int ) ( Math . Log ( n ) / Math . Log ( 2 ) ) ; return cuts ; } public static void Main ( String [ ] args ) { int n = 5 ; int cuts = pay ( n ) ; Console . Write ( cuts + " STRNEWLINE " ) ; n = 15 ; cuts = pay ( n ) ; Console . Write ( cuts ) ; } }
Sum of Maximum and Minimum prime factor of every number in the Array | C # implementation of the approach ; max_prime [ i ] represent maximum prime number that divides the number i ; min_prime [ i ] represent minimum prime number that divides the number i ; Function to store the minimum prime factor and the maximum prime factor in two arrays ; Check for prime number if min_prime [ i ] > 0 , then it is not a prime number ; if i is a prime number min_prime number that divide prime number and max_prime number that divide prime number is the number itself . ; If this number is being visited for first time then this divisor must be the smallest prime number that divides this number ; The last prime number that divides this number will be maximum . ; Function to find the sum of the minimum and the maximum prime factors of every number from the given array ; Pre - calculation ; For every element of the given array ; The sum of its smallest and largest prime factor ; Driver code
using System ; class GFG { static int MAX = 100000 ; static int [ ] max_prime = new int [ MAX + 1 ] ; static int [ ] min_prime = new int [ MAX + 1 ] ; static void sieve ( int n ) { for ( int i = 2 ; i <= n ; ++ i ) { if ( min_prime [ i ] > 0 ) { continue ; } min_prime [ i ] = i ; max_prime [ i ] = i ; int j = i + i ; while ( j <= n ) { if ( min_prime [ j ] == 0 ) { min_prime [ j ] = i ; } max_prime [ j ] = i ; j += i ; } } } static void findSum ( int [ ] arr , int n ) { sieve ( MAX ) ; for ( int i = 0 ; i < n ; i ++ ) { int sum = min_prime [ arr [ i ] ] + max_prime [ arr [ i ] ] ; Console . Write ( sum + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 10 , 15 , 20 , 25 , 30 } ; int n = arr . Length ; findSum ( arr , n ) ; } }
Pair of integers ( a , b ) which satisfy the given equations | C # program to count the pair of integers ( a , b ) which satisfy the equation a ^ 2 + b = n and a + b ^ 2 = m ; Function to count valid pairs ; Driver code
using System ; class GFG { static int pairCount ( int n , int m ) { int cnt = 0 , b , a ; for ( b = 0 ; b <= Math . Sqrt ( m ) ; b ++ ) { a = m - b * b ; if ( a * a + b == n ) { cnt ++ ; } } return cnt ; } public static void Main ( String [ ] args ) { int n = 9 , m = 3 ; Console . Write ( pairCount ( n , m ) + " STRNEWLINE " ) ; } }
Largest Divisor for each element in an array other than 1 and the number itself | C # implementation of the approach ; Divisors array to keep track of the maximum divisor ; Function to pre - compute the prime numbers and largest divisors ; Visited array to keep track of prime numbers ; 0 and 1 are not prime numbers ; Initialising divisors [ i ] = i ; For all the numbers divisible by 2 the maximum divisor will be number / 2 ; If divisors [ i ] is not equal to i then this means that divisors [ i ] contains minimum prime divisor for the number ; Update the answer to i / smallest_prime_divisor [ i ] ; Condition if i is a prime number ; If divisors [ j ] is equal to j then this means that i is the first prime divisor for j so we update divi [ j ] = i ; If the current element is prime then it has no divisors other than 1 and itself ; Driver code
using System ; class GFG { static int maxin = 10001 ; static int [ ] divisors = new int [ maxin + 1 ] ; static void Calc_Max_Div ( int [ ] arr , int n ) { int [ ] vis = new int [ maxin + 1 ] ; for ( int i = 0 ; i < maxin + 1 ; i ++ ) vis [ i ] = 1 ; vis [ 0 ] = vis [ 1 ] = 0 ; for ( int i = 1 ; i <= maxin ; i ++ ) divisors [ i ] = i ; for ( int i = 4 ; i <= maxin ; i += 2 ) { vis [ i ] = 0 ; divisors [ i ] = i / 2 ; } for ( int i = 3 ; i <= maxin ; i += 2 ) { if ( divisors [ i ] != i ) { divisors [ i ] = i / divisors [ i ] ; } if ( vis [ i ] == 1 ) { for ( int j = i * i ; j < maxin ; j += i ) { vis [ j ] = 0 ; if ( divisors [ j ] == j ) divisors [ j ] = i ; } } } for ( int i = 0 ; i < n ; i ++ ) { if ( divisors [ arr [ i ] ] == arr [ i ] ) Console . Write ( " - 1 ▁ " ) ; else Console . Write ( divisors [ arr [ i ] ] + " ▁ " ) ; } } public static void Main ( ) { int [ ] arr = { 5 , 6 , 7 , 8 , 9 , 10 } ; int n = arr . Length ; Calc_Max_Div ( arr , n ) ; } }
Given a number N in decimal base , find the sum of digits in any base B | C # Implementation to Compute Sum of Digits of Number N in Base B ; Function to compute sum of Digits of Number N in base B ; Initialize sum with 0 ; Compute unit digit of the number ; Add unit digit in sum ; Update value of Number ; Driver code
using System ; class GFG { static int sumOfDigit ( int n , int b ) { int unitDigit , sum = 0 ; while ( n > 0 ) { unitDigit = n % b ; sum += unitDigit ; n = n / b ; } return sum ; } public static void Main ( String [ ] args ) { int n = 50 ; int b = 2 ; Console . Write ( sumOfDigit ( n , b ) ) ; } }
Find the Nth digit from right in base B of the given number in Decimal base | C # Implementation to find Nth digit from right in base B ; Function to compute Nth digit from right in base B ; Skip N - 1 Digits in Base B ; Nth Digit from right in Base B ; Driver Code
using System ; class GFG { static int nthDigit ( int a , int n , int b ) { for ( int i = 1 ; i < n ; i ++ ) a = a / b ; return a % b ; } public static void Main ( ) { int a = 100 ; int n = 3 ; int b = 4 ; Console . Write ( nthDigit ( a , n , b ) ) ; } }
Find three prime numbers with given sum | C # implementation of the approach ; The vector primes holds the prime numbers ; Function to generate prime numbers ; Initialize the array elements to 0 s ; Set the non - primes to true ; Fill the vector primes with prime numbers which are marked as false in the numbers array ; Function to print three prime numbers which sum up to the number N ; Take the first prime number ; Take the second prime number ; Subtract the two prime numbers from the N to obtain the third number ; If the third number is prime ; Print the three prime numbers if the solution exists ; Driver code ; Function for generating prime numbers using Sieve of Eratosthenes ; Function to print the three prime numbers whose sum is equal to N
using System ; using System . Collections . Generic ; class GFG { static int MAX = 100001 ; static List < int > primes = new List < int > ( ) ; static void initialize ( ) { bool [ ] numbers = new bool [ MAX + 1 ] ; int n = MAX ; for ( int i = 2 ; i * i <= n ; i ++ ) if ( ! numbers [ i ] ) for ( int j = i * i ; j <= n ; j += i ) numbers [ j ] = true ; for ( int i = 2 ; i <= n ; i ++ ) if ( numbers [ i ] == false ) primes . Add ( i ) ; } static void findNums ( int num ) { bool ans = false ; int first = - 1 , second = - 1 , third = - 1 ; for ( int i = 0 ; i < num ; i ++ ) { first = primes [ i ] ; for ( int j = 0 ; j < num ; j ++ ) { second = primes [ j ] ; third = num - first - second ; if ( Array . BinarySearch ( primes . ToArray ( ) , third ) >= 0 ) { ans = true ; break ; } } if ( ans ) break ; } if ( ans ) Console . WriteLine ( first + " ▁ " + second + " ▁ " + third ) ; else Console . WriteLine ( - 1 ) ; } static void Main ( ) { int n = 101 ; initialize ( ) ; findNums ( n ) ; } }
Print all maximal increasing contiguous sub | C # Implementation to print all the Maximal Increasing Sub - array of array ; Function to print each of maximal contiguous increasing subarray ; Loop to iterate through the array and print the maximal contiguous increasing subarray . ; Condition to check whether the element at i , is greater than its next neighbouring element or not . ; Driver code
using System ; class GFG { static void printmaxSubseq ( int [ ] arr , int n ) { int i ; for ( i = 0 ; i < n ; i ++ ) { if ( i + 1 < n && arr [ i ] < arr [ i + 1 ] ) Console . Write ( arr [ i ] + " ▁ " ) ; else Console . WriteLine ( arr [ i ] ) ; } } public static void Main ( ) { int [ ] arr = { 9 , 8 , 11 , 13 , 10 , 15 , 14 , 16 , 20 , 5 } ; int n = arr . Length ; printmaxSubseq ( arr , n ) ; } }
Count of non decreasing arrays of length N formed with values in range L to R | C # implementation of the approach ; Function to return the count of different arrays ; No such combination exists ; Arrays formed with single elements ; Driver code
using System ; class GFG { static int countSum ( int N , int L , int R ) { if ( L > R ) { return 0 ; } if ( N == 1 ) { return R - L + 1 ; } if ( N > 1 ) { return ( N - 2 ) * ( R - L ) + 1 ; } return 0 ; } public static void Main ( String [ ] args ) { int N = 4 , L = 4 , R = 6 ; Console . Write ( countSum ( N , L , R ) ) ; } }
Minimum decrement operations to make Array elements equal by only decreasing K each time | C # implementation of the above approach ; Finding the minimum element ; Loop over all the elements and find the difference ; Solution found and returned ; Driver code
using System ; class GFG { static int INT_MAX = int . MaxValue ; static int solve ( int [ ] arr , int n , int k ) { int minx = INT_MAX ; int i ; for ( i = 0 ; i < n ; i ++ ) { minx = Math . Min ( minx , arr [ i ] ) ; } int decrements = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] - minx ) % k != 0 ) { return - 1 ; } else { decrements += ( ( arr [ i ] - minx ) / k ) ; } } return decrements ; } public static void Main ( ) { int n , k ; n = 3 ; k = 3 ; int [ ] arr = { 12 , 9 , 15 } ; Console . WriteLine ( solve ( arr , n , k ) ) ; } }
Count non decreasing subarrays of size N from N Natural numbers | C # program to count non decreasing subarrays of size N from N Natural numbers ; Returns value of Binomial Coefficient C ( n , k ) ; Since nC0 is 1 ; Compute next row of pascal triangle using the previous row ; Function to find the count of required subarrays ; The required count is the binomial coefficient as explained in the approach above ; Driver Function
using System ; class GFG { static int binomialCoeff ( int n , int k ) { int [ ] C = new int [ k + 1 ] ; C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . Min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } static int count_of_subarrays ( int N ) { int count = binomialCoeff ( 2 * N - 1 , N ) ; return count ; } public static void Main ( ) { int N = 3 ; Console . WriteLine ( count_of_subarrays ( N ) ) ; } }
Length of Smallest subarray in range 1 to N with sum greater than a given value | C # implementation of the above approach . ; Function to do a binary search on a given range . ; Total sum is the sum of N numbers . ; Sum until mid ; If remaining sum is < the required value , then the required number is in the right half ; Driver code
using System ; class GFG { static int usingBinarySearch ( int start , int end , int N , int S ) { if ( start >= end ) return start ; int mid = start + ( end - start ) / 2 ; int totalSum = ( N * ( N + 1 ) ) / 2 ; int midSum = ( mid * ( mid + 1 ) ) / 2 ; if ( ( totalSum - midSum ) <= S ) { return usingBinarySearch ( start , mid , N , S ) ; } return usingBinarySearch ( mid + 1 , end , N , S ) ; } public static void Main ( ) { int N , S ; N = 5 ; S = 11 ; Console . WriteLine ( N - usingBinarySearch ( 1 , N , N , S ) + 1 ) ; } }
Distribution of a Number in Array within a Range | C # implementation of the approach ; Function for the distribution of the number ; Distribute the number among k elements ; If there is some remaining sum to distribute ; If there are elements remaining to distribute i . e . ( n - k ) ; Divide the remaining sum into n - k elements ; Print the distribution ; Driver code
using System ; class GFG { static void distribution ( int n , int k , int l , int r , int S , int Sk ) { int [ ] a = new int [ n ] ; int len = k , temp , rem ; int diff = S - Sk ; for ( int i = 0 ; i < len ; i ++ ) { temp = Sk / k ; rem = Sk % k ; if ( temp + rem >= l && temp + rem <= r ) { a [ i ] = temp ; } else if ( temp + rem > r ) { a [ i ] = r ; } else if ( temp + rem < r ) { Console . Write ( " - 1" ) ; return ; } Sk = Sk - a [ i ] ; k = k - 1 ; } if ( Sk > 0 ) { Console . Write ( " - 1" ) ; return ; } if ( len != 0 ) { k = n - len ; for ( int i = len ; i < n ; i ++ ) { temp = diff / k ; rem = diff % k ; if ( temp + rem >= l && temp + rem <= r ) { a [ i ] = temp ; } else if ( temp + rem > r ) { a [ i ] = r ; } else if ( temp + rem < r ) { Console . Write ( " - 1" ) ; return ; } diff = diff - a [ i ] ; k = k - 1 ; } if ( diff != 0 ) { Console . Write ( " - 1" ) ; return ; } } for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( a [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int n = 5 , k = 3 , l = 1 , r = 5 , S = 13 , Sk = 9 ; distribution ( n , k , l , r , S , Sk ) ; } }
Number of valid indices in the permutation of first N natural numbers | C # implementation of the approach ; Function to return the number of i 's  such that Pi <= Pj for all 1 <= j <= i  in the permutation of first N natural numbers ; To store the count of such indices ; Store the mini value ; For all the elements ; Return the required answer ; Driver code
using System ; class GFG { static int INT_MAX = int . MaxValue ; static int min_index ( int [ ] p , int n ) { int ans = 0 ; int mini = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] <= mini ) mini = p [ i ] ; if ( mini == p [ i ] ) ans ++ ; } return ans ; } public static void Main ( ) { int [ ] P = { 4 , 2 , 5 , 1 , 3 } ; int n = P . Length ; Console . WriteLine ( min_index ( P , n ) ) ; } }
Check if Sum and XOR of all elements of array is equal | C # Implementation to Check if Sum and XOR of all Elements of Array is equal ; Function to Check if Sum and XOR of all elements of array is equal ; Sum and XOR of all elements ; Checking Sum and XOR to be equal ; Driver Function ; Check Sum and XOR is equal
using System ; class GFG { static void equal_xor_sum ( int [ ] arr , int n ) { int Sum = 0 ; int Xor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { Sum = Sum + arr [ i ] ; Xor = Xor ^ arr [ i ] ; } if ( Sum == Xor ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } public static void Main ( ) { int [ ] arr = { 6 , 3 , 7 , 10 } ; int n = arr . Length ; equal_xor_sum ( arr , n ) ; } }