dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; public class GfG { public static int find ( int n , int k ) { if ( n + 1 >= k ) return ( k - 1 ) ; else return ( 2 * n + 1 - k ) ; } public static void Main ( ) { int n = 4 , k = 7 ; int freq = find ( n , k ) ; if ( freq < 0 ) Console . WriteLine ( " ▁ element " + " ▁ not ▁ exist ▁ " ) ; else Console . WriteLine ( " ▁ Frequency " + " ▁ of ▁ " + k + " ▁ is ▁ " + freq ) ; } }

Class/struct names: GfG
C# program:
using System ; public class GfG { public static void ZigZag ( int rows , int columns , int [ ] numbers ) { int k = 0 ; int [ , ] arr = new int [ rows , columns ] ; for ( int i = 0 ; i < rows ; i ++ ) { if ( i % 2 == 0 ) { for ( int j = 0 ; j < columns && numbers [ k ] > 0 ; j ++ ) { arr [ i , j ] = k + 1 ; numbers [ k ] -- ; if ( numbers [ k ] == 0 ) k ++ ; } } else { for ( int j = columns - 1 ; j >= 0 && numbers [ k ] > 0 ; j -- ) { arr [ i , j ] = k + 1 ; numbers [ k ] -- ; if ( numbers [ k ] == 0 ) k ++ ; } } } for ( int i = 0 ; i < rows ; i ++ ) { for ( int j = 0 ; j < columns ; j ++ ) Console . Write ( arr [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int rows = 4 ; int columns = 5 ; int [ ] Numbers = new int [ ] { 3 , 4 , 2 , 2 , 3 , 1 , 5 } ; ZigZag ( rows , columns , Numbers ) ; } }

Index/key variables: k
Accumulator variables: i, j, k
Iterator variables: i, j
Class/struct names: GfG
C# program:
using System ; class GFG { static int numberofPosition ( int n , int k , int x , int y , int [ ] obstPosx , int [ ] obstPosy ) { int d11 , d12 , d21 , d22 , r1 , r2 , c1 , c2 ; d11 = Math . Min ( x - 1 , y - 1 ) ; d12 = Math . Min ( n - x , n - y ) ; d21 = Math . Min ( n - x , y - 1 ) ; d22 = Math . Min ( x - 1 , n - y ) ; r1 = y - 1 ; r2 = n - y ; c1 = x - 1 ; c2 = n - x ; for ( int i = 0 ; i < k ; i ++ ) { if ( x > obstPosx [ i ] && y > obstPosy [ i ] && x - obstPosx [ i ] == y - obstPosy [ i ] ) d11 = Math . Min ( d11 , x - obstPosx [ i ] - 1 ) ; if ( obstPosx [ i ] > x && obstPosy [ i ] > y && obstPosx [ i ] - x == obstPosy [ i ] - y ) d12 = Math . Min ( d12 , obstPosx [ i ] - x - 1 ) ; if ( obstPosx [ i ] > x && y > obstPosy [ i ] && obstPosx [ i ] - x == y - obstPosy [ i ] ) d21 = Math . Min ( d21 , obstPosx [ i ] - x - 1 ) ; if ( x > obstPosx [ i ] && obstPosy [ i ] > y && x - obstPosx [ i ] == obstPosy [ i ] - y ) d22 = Math . Min ( d22 , x - obstPosx [ i ] - 1 ) ; if ( x == obstPosx [ i ] && obstPosy [ i ] < y ) r1 = Math . Min ( r1 , y - obstPosy [ i ] - 1 ) ; if ( x == obstPosx [ i ] && obstPosy [ i ] > y ) r2 = Math . Min ( r2 , obstPosy [ i ] - y - 1 ) ; if ( y == obstPosy [ i ] && obstPosx [ i ] < x ) c1 = Math . Min ( c1 , x - obstPosx [ i ] - 1 ) ; if ( y == obstPosy [ i ] && obstPosx [ i ] > x ) c2 = Math . Min ( c2 , obstPosx [ i ] - x - 1 ) ; } return d11 + d12 + d21 + d22 + r1 + r2 + c1 + c2 ; } public static void Main ( ) { int n = 8 ; int k = 1 ; int Qposx = 4 ; int Qposy = 4 ; int [ ] obstPosx = { 3 } ; int [ ] obstPosy = { 5 } ; Console . WriteLine ( numberofPosition ( n , k , Qposx , Qposy , obstPosx , obstPosy ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static int n = 5 ; static int FindMaxProduct ( int [ , ] arr , int n ) { int max = 0 , result ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( ( j - 3 ) >= 0 ) { result = arr [ i , j ] * arr [ i , j - 1 ] * arr [ i , j - 2 ] * arr [ i , j - 3 ] ; if ( max < result ) max = result ; } if ( ( i - 3 ) >= 0 ) { result = arr [ i , j ] * arr [ i - 1 , j ] * arr [ i - 2 , j ] * arr [ i - 3 , j ] ; if ( max < result ) max = result ; } if ( ( i - 3 ) >= 0 && ( j - 3 ) >= 0 ) { result = arr [ i , j ] * arr [ i - 1 , j - 1 ] * arr [ i - 2 , j - 2 ] * arr [ i - 3 , j - 3 ] ; if ( max < result ) max = result ; } if ( ( i - 3 ) >= 0 && ( j - 1 ) <= 0 ) { result = arr [ i , j ] * arr [ i - 1 , j + 1 ] * arr [ i - 2 , j + 2 ] * arr [ i - 3 , j + 3 ] ; if ( max < result ) max = result ; } } } return max ; } static public void Main ( ) { int [ , ] arr = { { 1 , 2 , 3 , 4 , 5 } , { 6 , 7 , 8 , 9 , 1 } , { 2 , 3 , 4 , 5 , 6 } , { 7 , 8 , 9 , 1 , 0 } , { 9 , 6 , 4 , 2 , 3 } } ; Console . Write ( FindMaxProduct ( arr , n ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static int maxPro ( int [ , ] a , int n , int m , int k ) { int maxi = 1 , mp = 1 ; for ( int i = 0 ; i < n ; ++ i ) { int wp = 1 ; for ( int l = 0 ; l < k ; ++ l ) { wp *= a [ i , l ] ; } mp = wp ; for ( int j = k ; j < m ; ++ j ) { wp = wp * a [ i , j ] / a [ i , j - k ] ; maxi = Math . Max ( maxi , Math . Max ( mp , wp ) ) ; } } return maxi ; } static public void Main ( ) { int n = 6 , m = 5 , k = 4 ; int [ , ] a = { { 1 , 2 , 3 , 4 , 5 } , { 6 , 7 , 8 , 9 , 1 } , { 2 , 3 , 4 , 5 , 6 } , { 7 , 8 , 9 , 1 , 0 } , { 9 , 6 , 4 , 2 , 3 } , { 1 , 1 , 2 , 1 , 1 } } ; int maxpro = maxPro ( a , n , m , k ) ; Console . WriteLine ( maxpro ) ; } }

Accumulator variables: wp
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node left , right ; } ; static Node buildUtil ( int [ ] init , int [ ] post , int inStrt , int inEnd ) { if ( inStrt > inEnd ) return null ; int curr = post [ index ] ; Node node = newNode ( curr ) ; ( index ) -- ; if ( inStrt == inEnd ) return node ; int iIndex = mp [ curr ] ; node . right = buildUtil ( init , post , iIndex + 1 , inEnd ) ; node . left = buildUtil ( init , post , inStrt , iIndex - 1 ) ; return node ; } static Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; static int index ; static Node buildTree ( int [ ] init , int [ ] post , int len ) { for ( int i = 0 ; i < len ; i ++ ) mp . Add ( init [ i ] , i ) ; index = len - 1 ; return buildUtil ( init , post , 0 , len - 1 ) ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return ( node ) ; } static void preOrder ( Node node ) { if ( node == null ) return ; Console . Write ( node . data + " ▁ " ) ; preOrder ( node . left ) ; preOrder ( node . right ) ; } public static void Main ( String [ ] args ) { int [ ] init = { 4 , 8 , 2 , 5 , 1 , 6 , 3 , 7 } ; int [ ] post = { 8 , 4 , 5 , 2 , 6 , 7 , 3 , 1 } ; int n = init . Length ; Node root = buildTree ( init , post , n ) ; Console . Write ( " Preorder ▁ of ▁ the ▁ constructed ▁ tree ▁ : ▁ STRNEWLINE " ) ; preOrder ( root ) ; } }

Index/key variables: curr, i, index
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
C# program:
using System ; class GFG { static int minimumflip ( int [ , ] mat , int n ) { int [ , ] transpose = new int [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) transpose [ i , j ] = mat [ j , i ] ; int flip = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( transpose [ i , j ] != mat [ i , j ] ) flip ++ ; return flip / 2 ; } public static void Main ( ) { int n = 3 ; int [ , ] mat = { { 0 , 0 , 1 } , { 1 , 1 , 1 } , { 1 , 0 , 0 } } ; Console . WriteLine ( minimumflip ( mat , n ) ) ; } }

Accumulator variables: flip, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int minimumflip ( int [ , ] mat , int n ) { int flip = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) if ( mat [ i , j ] != mat [ j , i ] ) flip ++ ; return flip ; } public static void Main ( ) { int n = 3 ; int [ , ] mat = { { 0 , 0 , 1 } , { 1 , 1 , 1 } , { 1 , 0 , 0 } } ; Console . WriteLine ( minimumflip ( mat , n ) ) ; } }

Accumulator variables: flip, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100 ; static void freq ( int [ , ] ar , int m , int n ) { int even = 0 , odd = 0 ; for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 0 ; j < n ; ++ j ) { if ( ( ar [ i , j ] % 2 ) == 0 ) ++ even ; else ++ odd ; } } Console . WriteLine ( " ▁ Frequency ▁ of ▁ odd ▁ number ▁ = " + odd ) ; Console . WriteLine ( " ▁ Frequency ▁ of ▁ even ▁ number ▁ = ▁ " + even ) ; } public static void Main ( ) { int m = 3 , n = 3 ; int [ , ] array = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; freq ( array , m , n ) ; } }

Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static bool HalfDiagonalSums ( int [ , ] mat , int n ) { int diag1_left = 0 , diag1_right = 0 ; int diag2_left = 0 , diag2_right = 0 ; for ( int i = 0 , j = n - 1 ; i < n ; i ++ , j -- ) { if ( i < n / 2 ) { diag1_left += mat [ i , i ] ; diag2_left += mat [ j , i ] ; } else if ( i > n / 2 ) { diag1_right += mat [ i , i ] ; diag2_right += mat [ j , i ] ; } } return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 , n / 2 ] ) ; } static public void Main ( ) { int [ , ] a = { { 2 , 9 , 1 , 4 , - 2 } , { 6 , 7 , 2 , 11 , 4 } , { 4 , 2 , 9 , 2 , 4 } , { 1 , 9 , 2 , 4 , 4 } , { 0 , 2 , 4 , 2 , 5 } } ; Console . WriteLine ( HalfDiagonalSums ( a , 5 ) ? " Yes " : " No " ) ; } }

Accumulator variables: diag1_left, diag1_right, diag2_left, diag2_right, i, j
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int identity ( int num ) { int row , col ; for ( row = 0 ; row < num ; row ++ ) { for ( col = 0 ; col < num ; col ++ ) { if ( row == col ) Console . Write ( 1 + " ▁ " ) ; else Console . Write ( 0 + " ▁ " ) ; } Console . WriteLine ( ) ; } return 0 ; } public static void Main ( ) { int size = 5 ; identity ( size ) ; } }

Accumulator variables: col, row
Iterator variables: col, row
Class/struct names: GFG
C# program:
using System ; class GFG { int MAX = 100 ; static bool isIdentity ( int [ , ] mat , int N ) { for ( int row = 0 ; row < N ; row ++ ) { for ( int col = 0 ; col < N ; col ++ ) { if ( row == col && mat [ row , col ] != 1 ) return false ; else if ( row != col && mat [ row , col ] != 0 ) return false ; } } return true ; } public static void Main ( ) { int N = 4 ; int [ , ] mat = { { 1 , 0 , 0 , 0 } , { 0 , 1 , 0 , 0 } , { 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 1 } } ; if ( isIdentity ( mat , N ) ) Console . WriteLine ( " Yes ▁ " ) ; else Console . WriteLine ( " No ▁ " ) ; } }

Accumulator variables: col, row
Iterator variables: col, row
Class/struct names: GFG
C# program:
using System ; class Example { static long mod = 100000007 ; static long modPower ( long a , long t , long mod ) { long now = a , ret = 1 ; while ( t > 0 ) { if ( t % 2 == 1 ) ret = now * ( ret % mod ) ; now = now * ( now % mod ) ; t >>= 1 ; } return ret ; } static long countWays ( int n , int m , int k ) { if ( n == 1 m == 1 ) return 1 ; else if ( ( n + m ) % 2 == 1 && k == - 1 ) return 0 ; return ( modPower ( modPower ( ( long ) 2 , n - 1 , mod ) , m - 1 , mod ) % mod ) ; } public static void Main ( ) { int n = 2 , m = 7 , k = 1 ; Console . WriteLine ( countWays ( n , m , k ) ) ; } }

Class/struct names: Example
C# program:
using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node left , right ; public Node ( int x ) { data = x ; left = right = null ; } } static Node buildTree ( int [ ] init , int [ ] post , int n ) { Stack < Node > st = new Stack < Node > ( ) ; HashSet < Node > s = new HashSet < Node > ( ) ; int postIndex = n - 1 ; Node root = null ; for ( int p = n - 1 , i = n - 1 ; p >= 0 ; ) { Node node = null ; do { node = new Node ( post [ p ] ) ; if ( root == null ) { root = node ; } if ( st . Count > 0 ) { if ( s . Contains ( st . Peek ( ) ) ) { s . Remove ( st . Peek ( ) ) ; st . Peek ( ) . left = node ; st . Pop ( ) ; } else { st . Peek ( ) . right = node ; } } st . Push ( node ) ; } while ( post [ p -- ] != init [ i ] && p >= 0 ) ; node = null ; while ( st . Count > 0 && i >= 0 && st . Peek ( ) . data == init [ i ] ) { node = st . Peek ( ) ; st . Pop ( ) ; i -- ; } if ( node != null ) { s . Add ( node ) ; st . Push ( node ) ; } } return root ; } static void preOrder ( Node node ) { if ( node == null ) return ; Console . Write ( node . data + " ▁ " ) ; preOrder ( node . left ) ; preOrder ( node . right ) ; } public static void Main ( String [ ] args ) { int [ ] init = { 4 , 8 , 2 , 5 , 1 , 6 , 3 , 7 } ; int [ ] post = { 8 , 4 , 5 , 2 , 6 , 7 , 3 , 1 } ; int n = init . Length ; Node root = buildTree ( init , post , n ) ; Console . Write ( " Preorder ▁ of ▁ the ▁ constructed ▁ tree ▁ : ▁ STRNEWLINE " ) ; preOrder ( root ) ; } }

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: p
Class/struct names: GFG, Node
C# program:
using System ; using System . Collections . Generic ; class GFG { static int MAX = 100 ; static void imageSwap ( int [ , ] mat , int n ) { int row = 0 ; for ( int j = 0 ; j < n ; j ++ ) { Stack < int > s = new Stack < int > ( ) ; int i = row , k = j ; while ( i < n && k >= 0 ) { s . Push ( mat [ i ++ , k -- ] ) ; } i = row ; k = j ; while ( i < n && k >= 0 ) { mat [ i ++ , k -- ] = s . Peek ( ) ; s . Pop ( ) ; } } int column = n - 1 ; for ( int j = 1 ; j < n ; j ++ ) { Stack < int > s = new Stack < int > ( ) ; int i = j , k = column ; while ( i < n && k >= 0 ) { s . Push ( mat [ i ++ , k -- ] ) ; } i = j ; k = column ; while ( i < n && k >= 0 ) { mat [ i ++ , k -- ] = s . Peek ( ) ; s . Pop ( ) ; } } } static void printMatrix ( 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 ( String [ ] args ) { int [ , ] mat = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; int n = 4 ; imageSwap ( mat , n ) ; printMatrix ( mat , n ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100 ; static void imageSwap ( int [ , ] mat , int n ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j <= i ; j ++ ) mat [ i , j ] = mat [ i , j ] + mat [ j , i ] - ( mat [ j , i ] = mat [ i , j ] ) ; } static void printMatrix ( 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 = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; int n = 4 ; imageSwap ( mat , n ) ; printMatrix ( mat , n ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int search ( int [ , ] mat , int n , int x ) { if ( n == 0 ) return - 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) if ( mat [ i , j ] == x ) { Console . Write ( " Element ▁ found ▁ at ▁ ( " + i + " , ▁ " + j + " ) STRNEWLINE " ) ; return 1 ; } } Console . Write ( " ▁ Element ▁ not ▁ found " ) ; return 0 ; } static public void Main ( ) { int [ , ] mat = { { 10 , 20 , 30 , 40 } , { 15 , 25 , 35 , 45 } , { 27 , 29 , 37 , 48 } , { 32 , 33 , 39 , 50 } } ; search ( mat , 4 , 29 ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { private static void search ( int [ , ] mat , int n , int x ) { int i = 0 , j = n - 1 ; while ( i < n && j >= 0 ) { if ( mat [ i , j ] == x ) { Console . Write ( " n ▁ Found ▁ at ▁ " + i + " , ▁ " + j ) ; return ; } if ( mat [ i , j ] > x ) j -- ; else i ++ ; } Console . Write ( " n ▁ Element ▁ not ▁ found " ) ; return ; } public static void Main ( ) { int [ , ] mat = { { 10 , 20 , 30 , 40 } , { 15 , 25 , 35 , 45 } , { 27 , 29 , 37 , 48 } , { 32 , 33 , 39 , 50 } } ; search ( mat , 4 , 29 ) ; } }

Accumulator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void fill0X ( int m , int n ) { int i , k = 0 , l = 0 ; int r = m , c = n ; char [ , ] a = new char [ m , n ] ; char x = ' X ' ; while ( k < m && l < n ) { for ( i = l ; i < n ; ++ i ) a [ k , i ] = x ; k ++ ; for ( i = k ; i < m ; ++ i ) a [ i , n - 1 ] = x ; n -- ; if ( k < m ) { for ( i = n - 1 ; i >= l ; -- i ) a [ m - 1 , i ] = x ; m -- ; } if ( l < n ) { for ( i = m - 1 ; i >= k ; -- i ) a [ i , l ] = x ; l ++ ; } x = ( x == '0' ) ? ' X ' : '0' ; } for ( i = 0 ; i < r ; i ++ ) { for ( int j = 0 ; j < c ; j ++ ) Console . Write ( a [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { Console . WriteLine ( " Output ▁ for " + " ▁ m ▁ = ▁ 5 , ▁ n ▁ = ▁ 6" ) ; fill0X ( 5 , 6 ) ; Console . WriteLine ( " Output ▁ for " + " ▁ m ▁ = ▁ 4 , ▁ n ▁ = ▁ 4" ) ; fill0X ( 4 , 4 ) ; Console . WriteLine ( " Output ▁ for " + " ▁ m ▁ = ▁ 3 , ▁ n ▁ = ▁ 4" ) ; fill0X ( 3 , 4 ) ; } }

Accumulator variables: i, j, k, l, m, n
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { public static int R = 5 , C = 4 ; public static void diagonalOrder ( int [ , ] arr , int n , int m ) { List < List < int > > ans = new List < List < int > > ( n + m - 1 ) ; for ( int i = 0 ; i < n + m - 1 ; i ++ ) { ans . Add ( new List < int > ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { ( ans [ i + j ] ) . Add ( arr [ i , j ] ) ; } } for ( int i = 0 ; i < ans . Count ; i ++ ) { for ( int j = ans [ i ] . Count - 1 ; j >= 0 ; j -- ) { Console . Write ( ans [ i ] [ j ] + " ▁ " ) ; } Console . WriteLine ( ) ; } } static public void Main ( ) { int n = 5 , m = 4 ; int [ , ] arr = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } , { 17 , 18 , 19 , 20 } , } ; diagonalOrder ( arr , n , m ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static int calculateEnergy ( int [ , ] mat , int n ) { int i_des , j_des , q ; int tot_energy = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { q = mat [ i , j ] / n ; i_des = q ; j_des = mat [ i , j ] - ( n * q ) ; tot_energy += Math . Abs ( i_des - i ) + Math . Abs ( j_des - j ) ; } } return tot_energy ; } public static void Main ( ) { int [ , ] mat = new int [ , ] { { 4 , 7 , 0 , 3 } , { 8 , 5 , 6 , 1 } , { 9 , 11 , 10 , 2 } , { 15 , 13 , 14 , 12 } } ; int n = 4 ; Console . Write ( " Total ▁ energy ▁ required ▁ = ▁ " + calculateEnergy ( mat , n ) + " ▁ units " ) ; } }

Accumulator variables: i, j, tot_energy
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static readonly int MAX = 100 ; static bool isUnique ( int [ , ] mat , int i , int j , int n , int m ) { int sumrow = 0 ; for ( int k = 0 ; k < m ; k ++ ) { sumrow += mat [ i , k ] ; if ( sumrow > 1 ) return false ; } int sumcol = 0 ; for ( int k = 0 ; k < n ; k ++ ) { sumcol += mat [ k , j ] ; if ( sumcol > 1 ) return false ; } return true ; } static int countUnique ( int [ , ] mat , int n , int m ) { int uniquecount = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( mat [ i , j ] != 0 && isUnique ( mat , i , j , n , m ) ) uniquecount ++ ; return uniquecount ; } static public void Main ( ) { int [ , ] mat = { { 0 , 1 , 0 , 0 } , { 0 , 0 , 1 , 0 } , { 1 , 0 , 0 , 1 } } ; Console . Write ( countUnique ( mat , 3 , 4 ) ) ; } }

Accumulator variables: i, j, k, sumcol, sumrow, uniquecount
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100 ; static int countUnique ( int [ , ] mat , int n , int m ) { int [ ] rowsum = new int [ n ] ; int [ ] colsum = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( mat [ i , j ] != 0 ) { rowsum [ i ] ++ ; colsum [ j ] ++ ; } int uniquecount = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( mat [ i , j ] != 0 && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ; return uniquecount ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 0 , 1 , 0 , 0 } , { 0 , 0 , 1 , 0 } , { 1 , 0 , 0 , 1 } } ; Console . Write ( countUnique ( mat , 3 , 4 ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j, uniquecount
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countCommon ( int [ , ] mat , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( mat [ i , i ] == mat [ i , n - i - 1 ] ) res ++ ; return res ; } public static void Main ( ) { int [ , ] mat = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; Console . WriteLine ( countCommon ( mat , 3 ) ) ; } }

Accumulator variables: i, res
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static bool areSumSame ( int [ , ] a , int n , int m ) { int sum1 = 0 , sum2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum1 = 0 ; sum2 = 0 ; for ( int j = 0 ; j < m ; j ++ ) { sum1 += a [ i , j ] ; sum2 += a [ j , i ] ; } if ( sum1 == sum2 ) return true ; } return false ; } public static void Main ( ) { int n = 4 ; int m = 4 ; int [ , ] M = { { 1 , 2 , 3 , 4 } , { 9 , 5 , 3 , 1 } , { 0 , 3 , 5 , 6 } , { 0 , 4 , 5 , 6 } } ; if ( areSumSame ( M , n , m ) == true ) Console . Write ( "1 STRNEWLINE " ) ; else Console . Write ( "0 STRNEWLINE " ) ; } }

Accumulator variables: i, j, sum1, sum2
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public class NodeTemp { public int data ; public NodeTemp next , child ; public NodeTemp ( int data ) { this . data = data ; next = child = null ; } } public static NodeTemp addSibling ( NodeTemp node , int data ) { if ( node == null ) { return null ; } while ( node . next != null ) { node = node . next ; } return ( node . next = new NodeTemp ( data ) ) ; } public static NodeTemp addChild ( NodeTemp node , int data ) { if ( node == null ) { return null ; } if ( node . child != null ) { return ( addSibling ( node . child , data ) ) ; } else { return ( node . child = new NodeTemp ( data ) ) ; } } public static void traverseTree ( NodeTemp root ) { if ( root == null ) { return ; } while ( root != null ) { Console . Write ( root . data + " ▁ " ) ; if ( root . child != null ) { traverseTree ( root . child ) ; } root = root . next ; } } public static void Main ( string [ ] args ) { NodeTemp root = new NodeTemp ( 10 ) ; NodeTemp n1 = addChild ( root , 2 ) ; NodeTemp n2 = addChild ( root , 3 ) ; NodeTemp n3 = addChild ( root , 4 ) ; NodeTemp n4 = addChild ( n3 , 6 ) ; NodeTemp n5 = addChild ( root , 5 ) ; NodeTemp n6 = addChild ( n5 , 7 ) ; NodeTemp n7 = addChild ( n5 , 8 ) ; NodeTemp n8 = addChild ( n5 , 9 ) ; traverseTree ( root ) ; } }

Class/struct names: GFG, NodeTemp
C# program:
using System ; class GFG { static int N = 4 ; static void findMax ( int [ , ] arr ) { int row = 0 , i , j ; for ( i = 0 , j = N - 1 ; i < N ; i ++ ) { while ( arr [ i , j ] == 1 && j >= 0 ) { row = i ; j -- ; } } Console . Write ( " Row ▁ number ▁ = ▁ " + ( row + 1 ) ) ; Console . Write ( " , ▁ MaxCount ▁ = ▁ " + ( N - 1 - j ) ) ; } public static void Main ( ) { int [ , ] arr = { { 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 0 } , { 0 , 1 , 1 , 1 } } ; findMax ( arr ) ; } }

Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG