dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; public class GfG { private static int N = 4 ; public static bool isUpperTriangularMatrix ( int [ , ] mat ) { for ( int i = 1 ; i < N ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) if ( mat [ i , j ] != 0 ) return false ; return true ; } public static void Main ( ) { int [ , ] mat = { { 1 , 3 , 5 , 3 } , { 0 , 4 , 6 , 2 } , { 0 , 0 , 2 , 5 } , { 0 , 0 , 0 , 6 } } ; if ( isUpperTriangularMatrix ( mat ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GfG
C# program:
using System ; class GFG { static int m = 3 ; static int n = 2 ; static long countSets ( int [ , ] a ) { long res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int u = 0 , v = 0 ; for ( int j = 0 ; j < m ; j ++ ) { if ( a [ i , j ] == 1 ) u ++ ; else v ++ ; } res += ( long ) ( Math . Pow ( 2 , u ) - 1 + Math . Pow ( 2 , v ) ) - 1 ; } for ( int i = 0 ; i < m ; i ++ ) { int u = 0 , v = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( a [ j , i ] == 1 ) u ++ ; else v ++ ; } res += ( long ) ( Math . Pow ( 2 , u ) - 1 + Math . Pow ( 2 , v ) ) - 1 ; } return res - ( n * m ) ; } public static void Main ( ) { int [ , ] a = { { 1 , 0 , 1 } , { 0 , 1 , 0 } } ; Console . WriteLine ( countSets ( a ) ) ; } }

Accumulator variables: i, j, res, u, v
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100 ; static void transpose ( int [ , ] mat , int [ , ] tr , int N ) { for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) tr [ i , j ] = mat [ j , i ] ; } static bool isSymmetric ( int [ , ] mat , int N ) { int [ , ] tr = new int [ N , MAX ] ; transpose ( mat , tr , N ) ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( mat [ i , j ] != tr [ i , j ] ) return false ; return true ; } public static void Main ( ) { int [ , ] mat = { { 1 , 3 , 5 } , { 3 , 2 , 4 } , { 5 , 4 , 1 } } ; if ( isSymmetric ( mat , 3 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static bool isSymmetric ( int [ , ] mat , int N ) { for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( mat [ i , j ] != mat [ j , i ] ) return false ; return true ; } public static void Main ( ) { int [ , ] mat = { { 1 , 3 , 5 } , { 3 , 2 , 4 } , { 5 , 4 , 1 } } ; if ( isSymmetric ( mat , 3 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " NO " ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int findNormal ( int [ , ] mat , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) sum += mat [ i , j ] * mat [ i , j ] ; return ( int ) Math . Sqrt ( sum ) ; } static int findTrace ( int [ , ] mat , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += mat [ i , i ] ; return sum ; } public static void Main ( ) { int [ , ] mat = { { 1 , 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 , 4 } , { 5 , 5 , 5 , 5 , 5 } , } ; Console . Write ( " Trace ▁ of ▁ Matrix ▁ = ▁ " + findTrace ( mat , 5 ) + " STRNEWLINE " ) ; Console . Write ( " Normal ▁ of ▁ Matrix ▁ = ▁ " + findNormal ( mat , 5 ) ) ; } }

Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static int maxDet ( int n ) { return ( 2 * n * n * n ) ; } void resMatrix ( int n ) { for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( i == 0 && j == 2 ) Console . Write ( "0 ▁ " ) ; else if ( i == 1 && j == 0 ) Console . Write ( "0 ▁ " ) ; else if ( i == 2 && j == 1 ) Console . Write ( "0 ▁ " ) ; else Console . Write ( n + " ▁ " ) ; } Console . WriteLine ( " " ) ; } } static public void Main ( String [ ] args ) { int n = 15 ; GFG geeks = new GFG ( ) ; Console . WriteLine ( " Maximum ▁ Determinant ▁ = ▁ " + maxDet ( n ) ) ; Console . WriteLine ( " Resultant ▁ Matrix ▁ : " ) ; geeks . resMatrix ( n ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countNegative ( int [ , ] M , int n , int m ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( M [ i , j ] < 0 ) count += 1 ; else break ; } } return count ; } public static void Main ( ) { int [ , ] M = { { - 3 , - 2 , - 1 , 1 } , { - 2 , 2 , 3 , 4 } , { 4 , 5 , 7 , 8 } } ; Console . WriteLine ( countNegative ( M , 3 , 4 ) ) ; } }

Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countNegative ( int [ , ] M , int n , int m ) { int count = 0 ; int i = 0 ; int j = m - 1 ; while ( j >= 0 && i < n ) { if ( M [ i , j ] < 0 ) { count += j + 1 ; i += 1 ; } else j -= 1 ; } return count ; } public static void Main ( ) { int [ , ] M = { { - 3 , - 2 , - 1 , 1 } , { - 2 , 2 , 3 , 4 } , { 4 , 5 , 7 , 8 } } ; Console . WriteLine ( countNegative ( M , 3 , 4 ) ) ; } }

Accumulator variables: count, i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int getLastNegativeIndex ( int [ ] array , int start , int end ) { if ( start == end ) { return start ; } int mid = start + ( end - start ) / 2 ; if ( array [ mid ] < 0 ) { if ( mid + 1 < array . GetLength ( 0 ) && array [ mid + 1 ] >= 0 ) { return mid ; } return getLastNegativeIndex ( array , mid + 1 , end ) ; } else { return getLastNegativeIndex ( array , start , mid - 1 ) ; } } static int countNegative ( int [ , ] M , int n , int m ) { int count = 0 ; int nextEnd = m - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( M [ i , 0 ] >= 0 ) { break ; } nextEnd = getLastNegativeIndex ( GetRow ( M , i ) , 0 , nextEnd ) ; count += nextEnd + 1 ; } return count ; } public static int [ ] GetRow ( int [ , ] matrix , int row ) { var rowLength = matrix . GetLength ( 1 ) ; var rowVector = new int [ rowLength ] ; for ( var i = 0 ; i < rowLength ; i ++ ) rowVector [ i ] = matrix [ row , i ] ; return rowVector ; } public static void Main ( String [ ] args ) { int [ , ] M = { { - 3 , - 2 , - 1 , 1 } , { - 2 , 2 , 3 , 4 } , { 4 , 5 , 7 , 8 } } ; int r = M . GetLength ( 0 ) ; int c = M . GetLength ( 1 ) ; Console . WriteLine ( countNegative ( M , r , c ) ) ; } }

Index/key variables: i, mid, rowLength
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int findMaxValue ( int N , int [ , ] mat ) { int maxValue = int . MinValue ; for ( int a = 0 ; a < N - 1 ; a ++ ) for ( int b = 0 ; b < N - 1 ; b ++ ) for ( int d = a + 1 ; d < N ; d ++ ) for ( int e = b + 1 ; e < N ; e ++ ) if ( maxValue < ( mat [ d , e ] - mat [ a , b ] ) ) maxValue = mat [ d , e ] - mat [ a , b ] ; return maxValue ; } public static void Main ( ) { int N = 5 ; int [ , ] mat = { { 1 , 2 , - 1 , - 4 , - 20 } , { - 8 , - 3 , 4 , 2 , 1 } , { 3 , 8 , 6 , 1 , 3 } , { - 4 , - 1 , 1 , 7 , - 6 } , { 0 , - 4 , 10 , - 5 , 1 } } ; Console . Write ( " Maximum ▁ Value ▁ is ▁ " + findMaxValue ( N , mat ) ) ; } }

Accumulator variables: a, b, d, e
Iterator variables: a, b, d, e
Class/struct names: GFG
C# program:
using System ; class GFG { static int findMaxValue ( int N , int [ , ] mat ) { int maxValue = int . MinValue ; int [ , ] maxArr = new int [ N , N ] ; maxArr [ N - 1 , N - 1 ] = mat [ N - 1 , N - 1 ] ; int maxv = mat [ N - 1 , N - 1 ] ; for ( int j = N - 2 ; j >= 0 ; j -- ) { if ( mat [ N - 1 , j ] > maxv ) maxv = mat [ N - 1 , j ] ; maxArr [ N - 1 , j ] = maxv ; } maxv = mat [ N - 1 , N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) { if ( mat [ i , N - 1 ] > maxv ) maxv = mat [ i , N - 1 ] ; maxArr [ i , N - 1 ] = maxv ; } for ( int i = N - 2 ; i >= 0 ; i -- ) { for ( int j = N - 2 ; j >= 0 ; j -- ) { if ( maxArr [ i + 1 , j + 1 ] - mat [ i , j ] > maxValue ) maxValue = maxArr [ i + 1 , j + 1 ] - mat [ i , j ] ; maxArr [ i , j ] = Math . Max ( mat [ i , j ] , Math . Max ( maxArr [ i , j + 1 ] , maxArr [ i + 1 , j ] ) ) ; } } return maxValue ; } public static void Main ( ) { int N = 5 ; int [ , ] mat = { { 1 , 2 , - 1 , - 4 , - 20 } , { - 8 , - 3 , 4 , 2 , 1 } , { 3 , 8 , 6 , 1 , 3 } , { - 4 , - 1 , 1 , 7 , - 6 } , { 0 , - 4 , 10 , - 5 , 1 } } ; Console . Write ( " Maximum ▁ Value ▁ is ▁ " + findMaxValue ( N , mat ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int INF = int . MaxValue ; static int N = 4 ; static void youngify ( int [ , ] mat , int i , int j ) { int downVal = ( i + 1 < N ) ? mat [ i + 1 , j ] : INF ; int rightVal = ( j + 1 < N ) ? mat [ i , j + 1 ] : INF ; if ( downVal == INF && rightVal == INF ) { return ; } if ( downVal < rightVal ) { mat [ i , j ] = downVal ; mat [ i + 1 , j ] = INF ; youngify ( mat , i + 1 , j ) ; } else { mat [ i , j ] = rightVal ; mat [ i , j + 1 ] = INF ; youngify ( mat , i , j + 1 ) ; } } static int extractMin ( int [ , ] mat ) { int ret = mat [ 0 , 0 ] ; mat [ 0 , 0 ] = INF ; youngify ( mat , 0 , 0 ) ; return ret ; } static void printSorted ( int [ , ] mat ) { Console . WriteLine ( " Elements ▁ of ▁ matrix ▁ in ▁ sorted ▁ order ▁ n " ) ; for ( int i = 0 ; i < N * N ; i ++ ) { Console . Write ( extractMin ( mat ) + " ▁ " ) ; } } static public void Main ( ) { int [ , ] mat = { { 10 , 20 , 30 , 40 } , { 15 , 25 , 35 , 45 } , { 27 , 29 , 37 , 48 } , { 32 , 33 , 39 , 50 } } ; printSorted ( mat ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int n = 5 ; static void printSumSimple ( int [ , ] mat , int k ) { if ( k > n ) return ; for ( int i = 0 ; i < n - k + 1 ; i ++ ) { for ( int j = 0 ; j < n - k + 1 ; j ++ ) { int sum = 0 ; for ( int p = i ; p < k + i ; p ++ ) for ( int q = j ; q < k + j ; q ++ ) sum += mat [ p , q ] ; Console . Write ( sum + " ▁ " ) ; } Console . WriteLine ( ) ; } } public static void Main ( ) { int [ , ] mat = { { 1 , 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 , 4 } , { 5 , 5 , 5 , 5 , 5 } } ; int k = 3 ; printSumSimple ( mat , k ) ; } }

Accumulator variables: i, j, p, q, sum
Iterator variables: i, j, p, q
Class/struct names: GFG
C# program:
using System ; class GFG { static int n = 5 ; static void printSumTricky ( int [ , ] mat , int k ) { if ( k > n ) return ; int [ , ] stripSum = new int [ n , n ] ; for ( int j = 0 ; j < n ; j ++ ) { int sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) sum += mat [ i , j ] ; stripSum [ 0 , j ] = sum ; for ( int i = 1 ; i < n - k + 1 ; i ++ ) { sum += ( mat [ i + k - 1 , j ] - mat [ i - 1 , j ] ) ; stripSum [ i , j ] = sum ; } } for ( int i = 0 ; i < n - k + 1 ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < k ; j ++ ) sum += stripSum [ i , j ] ; Console . Write ( sum + " ▁ " ) ; for ( int j = 1 ; j < n - k + 1 ; j ++ ) { sum += ( stripSum [ i , j + k - 1 ] - stripSum [ i , j - 1 ] ) ; Console . Write ( sum + " ▁ " ) ; } Console . WriteLine ( ) ; } } public static void Main ( ) { int [ , ] mat = { { 1 , 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 , 4 } , { 5 , 5 , 5 , 5 , 5 } , } ; int k = 3 ; printSumTricky ( mat , k ) ; } }

Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int M = 3 ; static int N = 4 ; static void transpose ( int [ , ] A , int [ , ] B ) { int i , j ; for ( i = 0 ; i < N ; i ++ ) for ( j = 0 ; j < M ; j ++ ) B [ i , j ] = A [ j , i ] ; } public static void Main ( ) { int [ , ] A = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } } ; int [ , ] B = new int [ N , M ] ; transpose ( A , B ) ; Console . WriteLine ( " Result ▁ matrix ▁ is ▁ STRNEWLINE " ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) Console . Write ( B [ i , j ] + " ▁ " ) ; Console . Write ( " STRNEWLINE " ) ; } } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 4 ; static void transpose ( int [ , ] A ) { for ( int i = 0 ; i < N ; i ++ ) for ( int j = i + 1 ; j < N ; j ++ ) { int temp = A [ i , j ] ; A [ i , j ] = A [ j , i ] ; A [ j , i ] = temp ; } } public static void Main ( ) { int [ , ] A = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 } } ; transpose ( A ) ; Console . WriteLine ( " Modified ▁ matrix ▁ is ▁ " ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) Console . Write ( A [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { public const int R = 3 ; public const int C = 3 ; public static int pathCountRec ( int [ ] [ ] mat , int m , int n , int k ) { if ( m < 0 n < 0 ) { return 0 ; } if ( m == 0 && n == 0 && ( k == mat [ m ] [ n ] ) ) { return 1 ; } return pathCountRec ( mat , m - 1 , n , k - mat [ m ] [ n ] ) + pathCountRec ( mat , m , n - 1 , k - mat [ m ] [ n ] ) ; } public static int pathCount ( int [ ] [ ] mat , int k ) { return pathCountRec ( mat , R - 1 , C - 1 , k ) ; } public static void Main ( string [ ] args ) { int k = 12 ; int [ ] [ ] mat = new int [ ] [ ] { new int [ ] { 1 , 2 , 3 } , new int [ ] { 4 , 6 , 5 } , new int [ ] { 3 , 2 , 1 } } ; Console . WriteLine ( pathCount ( mat , k ) ) ; } }

Index/key variables: m, n
Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int R = 3 ; static readonly int C = 3 ; static readonly int MAX_K = 100 ; static int [ , , ] dp = new int [ R , C , MAX_K ] ; static int pathCountDPRecDP ( int [ , ] mat , int m , int n , int k ) { if ( m < 0 n < 0 ) return 0 ; if ( m == 0 && n == 0 ) return ( k == mat [ m , n ] ? 1 : 0 ) ; if ( dp [ m , n , k ] != - 1 ) return dp [ m , n , k ] ; dp [ m , n , k ] = pathCountDPRecDP ( mat , m - 1 , n , k - mat [ m , n ] ) + pathCountDPRecDP ( mat , m , n - 1 , k - mat [ m , n ] ) ; return dp [ m , n , k ] ; } static int pathCountDP ( int [ , ] mat , int k ) { for ( int i = 0 ; i < R ; i ++ ) for ( int j = 0 ; j < C ; j ++ ) for ( int l = 0 ; l < MAX_K ; l ++ ) dp [ i , j , l ] = - 1 ; return pathCountDPRecDP ( mat , R - 1 , C - 1 , k ) ; } public static void Main ( String [ ] args ) { int k = 12 ; int [ , ] mat = { { 1 , 2 , 3 } , { 4 , 6 , 5 } , { 3 , 2 , 1 } } ; Console . WriteLine ( pathCountDP ( mat , k ) ) ; } }

Accumulator variables: i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int SIZE = 10 ; static void sortMat ( int [ , ] mat , int n ) { int [ ] temp = new int [ n * n ] ; int k = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) temp [ k ++ ] = mat [ i , j ] ; Array . Sort ( temp ) ; k = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) mat [ i , j ] = temp [ k ++ ] ; } static void printMat ( int [ , ] mat , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) Console . Write ( mat [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int [ , ] mat = { { 5 , 4 , 7 } , { 1 , 3 , 8 } , { 2 , 9 , 6 } } ; int n = 3 ; Console . WriteLine ( " Original ▁ Matrix : " ) ; printMat ( mat , n ) ; sortMat ( mat , n ) ; Console . WriteLine ( " Matrix ▁ After ▁ Sorting : " ) ; printMat ( mat , n ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void sort ( int [ ] arr ) { int n = arr . Length ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int min_idx = i ; for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ j ] < arr [ min_idx ] ) min_idx = j ; int temp = arr [ min_idx ] ; arr [ min_idx ] = arr [ i ] ; arr [ i ] = temp ; } } static void printArray ( int [ ] arr ) { int n = arr . Length ; for ( int i = 0 ; i < n ; ++ i ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( ) { int [ ] arr = { 64 , 25 , 12 , 22 , 11 } ; sort ( arr ) ; Console . WriteLine ( " Sorted ▁ array " ) ; printArray ( arr ) ; } }

Index/key variables: i, j, min_idx
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void bubbleSort ( int [ ] arr , int n ) { int i , j , temp ; bool swapped ; for ( i = 0 ; i < n - 1 ; i ++ ) { swapped = false ; for ( j = 0 ; j < n - i - 1 ; j ++ ) { if ( arr [ j ] > arr [ j + 1 ] ) { temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; swapped = true ; } } if ( swapped == false ) break ; } } static void printArray ( int [ ] arr , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( ) { int [ ] arr = { 64 , 34 , 25 , 12 , 22 , 11 , 90 } ; int n = arr . Length ; bubbleSort ( arr , n ) ; Console . WriteLine ( " Sorted ▁ array " ) ; printArray ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: swapped
Class/struct names: GFG
C# program:
using System ; class GFG { static int findCrossOver ( int [ ] arr , int low , int high , int x ) { if ( arr [ high ] <= x ) return high ; if ( arr [ low ] > x ) return low ; int mid = ( low + high ) / 2 ; if ( arr [ mid ] <= x && arr [ mid + 1 ] > x ) return mid ; if ( arr [ mid ] < x ) return findCrossOver ( arr , mid + 1 , high , x ) ; return findCrossOver ( arr , low , mid - 1 , x ) ; } static void printKclosest ( int [ ] arr , int x , int k , int n ) { int l = findCrossOver ( arr , 0 , n - 1 , x ) ; int r = l + 1 ; int count = 0 ; if ( arr [ l ] == x ) l -- ; while ( l >= 0 && r < n && count < k ) { if ( x - arr [ l ] < arr [ r ] - x ) Console . Write ( arr [ l -- ] + " ▁ " ) ; else Console . Write ( arr [ r ++ ] + " ▁ " ) ; count ++ ; } while ( count < k && l >= 0 ) { Console . Write ( arr [ l -- ] + " ▁ " ) ; count ++ ; } while ( count < k && r < n ) { Console . Write ( arr [ r ++ ] + " ▁ " ) ; count ++ ; } } public static void Main ( ) { int [ ] arr = { 12 , 16 , 22 , 30 , 35 , 39 , 42 , 45 , 48 , 50 , 53 , 55 , 56 } ; int n = arr . Length ; int x = 35 ; printKclosest ( arr , x , 4 , n ) ; } }

Index/key variables: high, l, low, mid, r
Accumulator variables: count, l, r
Class/struct names: GFG
C# program:
using System ; public class LinkedlistIS { public node head ; public node sorted ; public class node { public int val ; public node next ; public node ( int val ) { this . val = val ; } } void push ( int val ) { node newnode = new node ( val ) ; newnode . next = head ; head = newnode ; } void insertionSort ( node headref ) { sorted = null ; node current = headref ; while ( current != null ) { node next = current . next ; sortedInsert ( current ) ; current = next ; } head = sorted ; } void sortedInsert ( node newnode ) { if ( sorted == null sorted . val >= newnode . val ) { newnode . next = sorted ; sorted = newnode ; } else { node current = sorted ; while ( current . next != null && current . next . val < newnode . val ) { current = current . next ; } newnode . next = current . next ; current . next = newnode ; } } void printlist ( node head ) { while ( head != null ) { Console . Write ( head . val + " ▁ " ) ; head = head . next ; } } public static void Main ( String [ ] args ) { LinkedlistIS list = new LinkedlistIS ( ) ; list . push ( 5 ) ; list . push ( 20 ) ; list . push ( 4 ) ; list . push ( 3 ) ; list . push ( 30 ) ; Console . WriteLine ( " Linked ▁ List ▁ before ▁ Sorting . . " ) ; list . printlist ( list . head ) ; list . insertionSort ( list . head ) ; Console . WriteLine ( " STRNEWLINE LinkedList ▁ After ▁ sorting " ) ; list . printlist ( list . head ) ; } }

Class/struct names: LinkedlistIS, node
C# program:
using System ; class GFG { static int count ( int [ ] S , int m , int n ) { if ( n == 0 ) return 1 ; if ( n < 0 ) return 0 ; if ( m <= 0 && n >= 1 ) return 0 ; return count ( S , m - 1 , n ) + count ( S , m , n - S [ m - 1 ] ) ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 } ; int m = arr . Length ; Console . Write ( count ( arr , m , 4 ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int count ( int [ ] S , int m , int n ) { int [ ] table = new int [ n + 1 ] ; table [ 0 ] = 1 ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = S [ i ] ; j <= n ; j ++ ) table [ j ] += table [ j - S [ i ] ] ; return table [ n ] ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 } ; int m = arr . Length ; int n = 4 ; Console . Write ( count ( arr , m , n ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , ] dp = new int [ 100 , 100 ] ; static int matrixChainMemoised ( int [ ] p , int i , int j ) { if ( i == j ) { return 0 ; } if ( dp [ i , j ] != - 1 ) { return dp [ i , j ] ; } dp [ i , j ] = Int32 . MaxValue ; for ( int k = i ; k < j ; k ++ ) { dp [ i , j ] = Math . Min ( dp [ i , j ] , matrixChainMemoised ( p , i , k ) + matrixChainMemoised ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ) ; } return dp [ i , j ] ; } static int MatrixChainOrder ( int [ ] p , int n ) { int i = 1 , j = n - 1 ; return matrixChainMemoised ( p , i , j ) ; } static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 } ; int n = arr . Length ; for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { dp [ i , j ] = - 1 ; } } Console . WriteLine ( " Minimum ▁ number ▁ of ▁ multiplications ▁ is ▁ " + MatrixChainOrder ( arr , n ) ) ; } }

Index/key variables: j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int MatrixChainOrder ( int [ ] p , int n ) { int [ , ] m = new int [ n , n ] ; int i , j , k , L , q ; for ( i = 1 ; i < n ; i ++ ) m [ i , i ] = 0 ; for ( L = 2 ; L < n ; L ++ ) { for ( i = 1 ; i < n - L + 1 ; i ++ ) { j = i + L - 1 ; if ( j == n ) continue ; m [ i , j ] = int . MaxValue ; for ( k = i ; k <= j - 1 ; k ++ ) { q = m [ i , k ] + m [ k + 1 , j ] + p [ i - 1 ] * p [ k ] * p [ j ] ; if ( q < m [ i , j ] ) m [ i , j ] = q ; } } } return m [ 1 , n - 1 ] ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 } ; int size = arr . Length ; Console . Write ( " Minimum ▁ number ▁ of ▁ " + " multiplications ▁ is ▁ " + MatrixChainOrder ( arr , size ) ) ; } }

Index/key variables: j, k
Accumulator variables: L, i, k
Iterator variables: L, i, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int cutRod ( int [ ] price , int n ) { if ( n <= 0 ) return 0 ; int max_val = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) max_val = Math . Max ( max_val , price [ i ] + cutRod ( price , n - i - 1 ) ) ; return max_val ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 } ; int size = arr . Length ; Console . WriteLine ( " Maximum ▁ Obtainable ▁ Value ▁ is ▁ " + cutRod ( arr , size ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int multiply ( int x , int y ) { if ( y == 0 ) return 0 ; if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ; if ( y < 0 ) return - multiply ( x , - y ) ; return - 1 ; } public static void Main ( ) { Console . WriteLine ( multiply ( 5 , - 11 ) ) ; } }

Class/struct names: GFG
C# program:
using System ; namespace prime { public class GFG { public static void SieveOfEratosthenes ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int i = 2 ; i <= n ; i ++ ) { if ( prime [ i ] == true ) Console . Write ( i + " ▁ " ) ; } } public static void Main ( ) { int n = 30 ; Console . WriteLine ( " Following ▁ are ▁ the ▁ prime ▁ numbers " ) ; Console . WriteLine ( " smaller ▁ than ▁ or ▁ equal ▁ to ▁ " + n ) ; SieveOfEratosthenes ( n ) ; } } }

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Class/struct names: GFG