codeparrot/xlcost-text-to-code huggingface dataset:
Find row number of a binary matrix having maximum number of 1 s | C # program to find row with maximum 1 in row sorted binary matrix ; function for finding row with maximum 1 ; find left most position of 1 in a row find 1 st zero in a row ; Driver code
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 ) ; } }
Find if a 2 | C # program to Find a 2 - D array is completely traversed or not by following the cell values ; Cell class constructor ; function which tells all cells are visited or not ; starting cell values ; if we get null before the end of loop then returns false . Because it means we didn 't traverse all the cells ; If found cycle then return false ; Update startx and starty values to next cell values ; finally if we reach our goal then returns true ; Driver Code
using System ; public class Cell { public int x ; public int y ; public Cell ( int x , int y ) { this . x = x ; this . y = y ; } } public class MoveCellPerCellValue { public Boolean isAllCellTraversed ( Cell [ , ] grid ) { Boolean [ , ] visited = new Boolean [ grid . GetLength ( 0 ) , grid . GetLength ( 1 ) ] ; int total = grid . GetLength ( 0 ) * grid . GetLength ( 1 ) ; int startx = grid [ 0 , 0 ] . x ; int starty = grid [ 0 , 0 ] . y ; for ( int i = 0 ; i < total - 2 ; i ++ ) { if ( grid [ startx , starty ] == null ) return false ; if ( visited [ startx , starty ] == true ) return false ; visited [ startx , starty ] = true ; int x = grid [ startx , starty ] . x ; int y = grid [ startx , starty ] . y ; startx = x ; starty = y ; } if ( grid [ startx , starty ] == null ) return true ; return false ; } public static void Main ( String [ ] args ) { Cell [ , ] cell = new Cell [ 3 , 2 ] ; cell [ 0 , 0 ] = new Cell ( 0 , 1 ) ; cell [ 0 , 1 ] = new Cell ( 2 , 0 ) ; cell [ 1 , 0 ] = null ; cell [ 1 , 1 ] = new Cell ( 1 , 0 ) ; cell [ 2 , 0 ] = new Cell ( 2 , 1 ) ; cell [ 2 , 1 ] = new Cell ( 1 , 1 ) ; MoveCellPerCellValue mcp = new MoveCellPerCellValue ( ) ; Console . WriteLine ( mcp . isAllCellTraversed ( cell ) ) ; } }
Print all palindromic paths from top left to bottom right in a matrix | C # program to print all palindromic paths from top left to bottom right in a grid . ; i and j are row and column indexes of current cell ( initially these are 0 and 0 ) . ; If we have not reached bottom right corner , keep exlporing ; If we reach bottom right corner , we check if the path used is palindrome or not . ; Driver code
using System ; class GFG { public static bool isPalin ( string str ) { int len = str . Length / 2 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] != str [ str . Length - i - 1 ] ) { return false ; } } return true ; } public static void palindromicPath ( string str , char [ ] [ ] a , int i , int j , int m , int n ) { if ( j < m - 1 i < n - 1 ) { if ( i < n - 1 ) { palindromicPath ( str + a [ i ] [ j ] , a , i + 1 , j , m , n ) ; } if ( j < m - 1 ) { palindromicPath ( str + a [ i ] [ j ] , a , i , j + 1 , m , n ) ; } } else { str = str + a [ n - 1 ] [ m - 1 ] ; if ( isPalin ( str ) ) { Console . WriteLine ( str ) ; } } } public static void Main ( string [ ] args ) { char [ ] [ ] arr = new char [ ] [ ] { new char [ ] { ' a ' , ' a ' , ' a ' , ' b ' } , new char [ ] { ' b ' , ' a ' , ' a ' , ' a ' } , new char [ ] { ' a ' , ' b ' , ' b ' , ' a ' } } ; string str = " " ; palindromicPath ( str , arr , 0 , 0 , 4 , 3 ) ; } }
Possible moves of knight | C # program to find number of possible moves of knight ; To calculate possible moves ; All possible moves of a knight ; Check if each possible move is valid or not ; Position of knight after move ; count valid moves ; Return number of possible moves ; Driver Code
using System ; class GFG { static int n = 4 ; static int m = 4 ; static int findPossibleMoves ( int [ , ] mat , int p , int q ) { int [ ] X = { 2 , 1 , - 1 , - 2 , - 2 , - 1 , 1 , 2 } ; int [ ] Y = { 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 , - 1 } ; int count = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { int x = p + X [ i ] ; int y = q + Y [ i ] ; if ( x >= 0 && y >= 0 && x < n && y < m && mat [ x , y ] == 0 ) count ++ ; } return count ; } static public void Main ( ) { int [ , ] mat = { { 1 , 0 , 1 , 0 } , { 0 , 1 , 1 , 1 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 1 } } ; int p = 2 , q = 2 ; Console . WriteLine ( findPossibleMoves ( mat , p , q ) ) ; } }
Efficiently compute sums of diagonals of a matrix | A simple C # program to find sum of diagonals ; Condition for principal diagonal ; Condition for secondary diagonal ; Driver code
using System ; public class GFG { static void printDiagonalSums ( int [ , ] mat , int n ) { int principal = 0 , secondary = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) principal += mat [ i , j ] ; if ( ( i + j ) == ( n - 1 ) ) secondary += mat [ i , j ] ; } } Console . WriteLine ( " Principal ▁ Diagonal : " + principal ) ; Console . WriteLine ( " Secondary ▁ Diagonal : " + secondary ) ; } static public void Main ( ) { int [ , ] a = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } } ; printDiagonalSums ( a , 4 ) ; } }
Efficiently compute sums of diagonals of a matrix | An efficient C # program to find sum of diagonals ; Driver code
using System ; public class GFG { static void printDiagonalSums ( int [ , ] mat , int n ) { int principal = 0 , secondary = 0 ; for ( int i = 0 ; i < n ; i ++ ) { principal += mat [ i , i ] ; secondary += mat [ i , n - i - 1 ] ; } Console . WriteLine ( " Principal ▁ Diagonal : " + principal ) ; Console . WriteLine ( " Secondary ▁ Diagonal : " + secondary ) ; } static public void Main ( ) { int [ , ] a = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } } ; printDiagonalSums ( a , 4 ) ; } }
Creating a tree with Left | C # program to create a tree with left child right sibling representation . ; Creating new Node ; Adds a sibling to a list with starting with n ; Add child Node to a Node ; Check if child list is not empty . ; Traverses tree in level order ; Corner cases ; Create a queue and enque root ; Take out an item from the queue ; Print next level of taken out item and enque next level 's children ; Driver code
using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node next ; public Node child ; } ; static Node newNode ( int data ) { Node newNode = new Node ( ) ; newNode . next = newNode . child = null ; newNode . data = data ; return newNode ; } static Node addSibling ( Node n , int data ) { if ( n == null ) return null ; while ( n . next != null ) n = n . next ; return ( n . next = newNode ( data ) ) ; } static Node addChild ( Node n , int data ) { if ( n == null ) return null ; if ( n . child != null ) return addSibling ( n . child , data ) ; else return ( n . child = newNode ( data ) ) ; } static void traverseTree ( Node root ) { if ( root == null ) return ; Console . Write ( root . data + " ▁ " ) ; if ( root . child == null ) return ; Queue < Node > q = new Queue < Node > ( ) ; Node curr = root . child ; q . Enqueue ( curr ) ; while ( q . Count != 0 ) { curr = q . Peek ( ) ; q . Dequeue ( ) ; while ( curr != null ) { Console . Write ( curr . data + " ▁ " ) ; if ( curr . child != null ) { q . Enqueue ( curr . child ) ; } curr = curr . next ; } } } public static void Main ( String [ ] args ) { Node root = newNode ( 10 ) ; Node n1 = addChild ( root , 2 ) ; Node n2 = addChild ( root , 3 ) ; Node n3 = addChild ( root , 4 ) ; Node n4 = addChild ( n3 , 6 ) ; Node n5 = addChild ( root , 5 ) ; Node n6 = addChild ( n5 , 7 ) ; Node n7 = addChild ( n5 , 8 ) ; Node n8 = addChild ( n5 , 9 ) ; traverseTree ( root ) ; } }
Boundary elements of a Matrix | C # Code for Boundary elements of a Matrix ; Driver Code
using System ; class GFG { public static void printBoundary ( int [ , ] a , int m , int n ) { for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == 0 ) Console . Write ( a [ i , j ] + " ▁ " ) ; else if ( i == m - 1 ) Console . Write ( a [ i , j ] + " ▁ " ) ; else if ( j == 0 ) Console . Write ( a [ i , j ] + " ▁ " ) ; else if ( j == n - 1 ) Console . Write ( a [ i , j ] + " ▁ " ) ; else Console . Write ( " ▁ " ) ; } Console . WriteLine ( " ▁ " ) ; } } static public void Main ( ) { int [ , ] a = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } } ; printBoundary ( a , 4 , 4 ) ; } }
Boundary elements of a Matrix | C # Code for Finding sum of boundary elements ; Driver Code
using System ; class GFG { public static long getBoundarySum ( int [ , ] a , int m , int n ) { long sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == 0 ) sum += a [ i , j ] ; else if ( i == m - 1 ) sum += a [ i , j ] ; else if ( j == 0 ) sum += a [ i , j ] ; else if ( j == n - 1 ) sum += a [ i , j ] ; } } return sum ; } static public void Main ( ) { int [ , ] a = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } } ; long sum = getBoundarySum ( a , 4 , 4 ) ; Console . WriteLine ( " Sum ▁ of ▁ boundary " + " ▁ elements ▁ is ▁ " + sum ) ; } }
Print a matrix in a spiral form starting from a point | C # program to print a matrix in spiral form ; Driver code ; Function calling
using System ; class GFG { static void printSpiral ( int [ , ] mat , int r , int c ) { int i , a = 0 , b = 2 ; int low_row = ( 0 > a ) ? 0 : a ; int low_column = ( 0 > b ) ? 0 : b - 1 ; int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ; int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ; while ( ( low_row > 0 - r && low_column > 0 - c ) ) { for ( i = low_column + 1 ; i <= high_column && i < c && low_row >= 0 ; ++ i ) Console . Write ( mat [ low_row , i ] + " ▁ " ) ; low_row -= 1 ; for ( i = low_row + 2 ; i <= high_row && i < r && high_column < c ; ++ i ) Console . Write ( mat [ i , high_column ] + " ▁ " ) ; high_column += 1 ; for ( i = high_column - 2 ; i >= low_column && i >= 0 && high_row < r ; -- i ) Console . Write ( mat [ high_row , i ] + " ▁ " ) ; high_row += 1 ; for ( i = high_row - 2 ; i > low_row && i >= 0 && low_column >= 0 ; -- i ) Console . Write ( mat [ i , low_column ] + " ▁ " ) ; low_column -= 1 ; } Console . WriteLine ( ) ; } static public void Main ( ) { int [ , ] mat = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; int r = 3 , c = 3 ; printSpiral ( mat , r , c ) ; } }
Program to Interchange Diagonals of Matrix | C # program to interchange the diagonals of matrix ; Function to interchange diagonals ; swap elements of diagonal ; Driver Code
using System ; class GFG { public static int N = 3 ; static void interchangeDiagonals ( int [ , ] array ) { for ( int i = 0 ; i < N ; ++ i ) if ( i != N / 2 ) { int temp = array [ i , i ] ; array [ i , i ] = array [ i , N - i - 1 ] ; array [ i , N - i - 1 ] = temp ; } for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) Console . Write ( array [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int [ , ] array = { { 4 , 5 , 6 } , { 1 , 2 , 3 } , { 7 , 8 , 9 } } ; interchangeDiagonals ( array ) ; } }
Find difference between sums of two diagonals | C # Code for find difference between sums of two diagonals ; Initialize sums of diagonals ; finding sum of primary diagonal ; finding sum of secondary diagonal ; Absolute difference of the sums across the diagonals ; Driver Code
using System ; public class GFG { public static int difference ( int [ , ] arr , int n ) { int d1 = 0 , d2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) d1 += arr [ i , j ] ; if ( i == n - j - 1 ) d2 += arr [ i , j ] ; } } return Math . Abs ( d1 - d2 ) ; } public static void Main ( ) { int n = 3 ; int [ , ] arr = { { 11 , 2 , 4 } , { 4 , 5 , 6 } , { 10 , 8 , - 12 } } ; Console . Write ( difference ( arr , n ) ) ; } }
Find difference between sums of two diagonals | C # Code for find difference between sums of two diagonals ; Initialize sums of diagonals ; Absolute difference of the sums across the diagonals ; Driver Code
using System ; public class GFG { public static int difference ( int [ , ] arr , int n ) { int d1 = 0 , d2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { d1 += arr [ i , i ] ; d2 += arr [ i , n - i - 1 ] ; } return Math . Abs ( d1 - d2 ) ; } public static void Main ( ) { int n = 3 ; int [ , ] arr = { { 11 , 2 , 4 } , { 4 , 5 , 6 } , { 10 , 8 , - 12 } } ; Console . Write ( difference ( arr , n ) ) ; } }
Circular Matrix ( Construct a matrix with numbers 1 to m * n in spiral way ) | C # program to fill a matrix with values from 1 to n * n in spiral fashion . ; Fills a [ m , n ] with values from 1 to m * n in spiral fashion . ; Initialize value to be filled in matrix ; k - starting row index m - ending row index l - starting column index n - ending column index ; Print the first row from the remaining rows ; Print the last column from the remaining columns ; Print the last row from the remaining rows ; Print the first column from the remaining columns ; Driver program to test above functions
using System ; class GFG { static int MAX = 100 ; static void spiralFill ( int m , int n , int [ , ] a ) { int val = 1 ; int k = 0 , l = 0 ; while ( k < m && l < n ) { for ( int i = l ; i < n ; ++ i ) { a [ k , i ] = val ++ ; } k ++ ; for ( int i = k ; i < m ; ++ i ) { a [ i , n - 1 ] = val ++ ; } n -- ; if ( k < m ) { for ( int i = n - 1 ; i >= l ; -- i ) { a [ m - 1 , i ] = val ++ ; } m -- ; } if ( l < n ) { for ( int i = m - 1 ; i >= k ; -- i ) { a [ i , l ] = val ++ ; } l ++ ; } } } public static void Main ( ) { int m = 4 , n = 4 ; int [ , ] a = new int [ MAX , MAX ] ; spiralFill ( m , n , a ) ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { Console . Write ( a [ i , j ] + " ▁ " ) ; } Console . Write ( " STRNEWLINE " ) ; } } }
Prufer Code to Tree Creation | C # program to construct tree from given Prufer Code ; Prints edges of tree represented by give Prufer code ; Initialize the array of vertices ; Number of occurrences of vertex in code ; Find the smallest label not present in prufer [ ] . ; If j + 1 is not present in prufer set ; Remove from Prufer set and print pair . ; For the last element ; Driver code
using System ; class GFG { static void printTreeEdges ( int [ ] prufer , int m ) { int vertices = m + 2 ; int [ ] vertex_set = new int [ vertices ] ; for ( int i = 0 ; i < vertices ; i ++ ) vertex_set [ i ] = 0 ; for ( int i = 0 ; i < vertices - 2 ; i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ; Console . Write ( " set ( G ) is : " int j = 0 ; for ( int i = 0 ; i < vertices - 2 ; i ++ ) { for ( j = 0 ; j < vertices ; j ++ ) { if ( vertex_set [ j ] == 0 ) { vertex_set [ j ] = - 1 ; Console . Write ( " ( " + ( j + 1 ) + " , ▁ " + prufer [ i ] + " ) ▁ " ) ; vertex_set [ prufer [ i ] - 1 ] -- ; break ; } } } j = 0 ; for ( int i = 0 ; i < vertices ; i ++ ) { if ( vertex_set [ i ] == 0 && j == 0 ) { Console . Write ( " ( " + ( i + 1 ) + " , ▁ " ) ; j ++ ; } else if ( vertex_set [ i ] == 0 && j == 1 ) Console . Write ( ( i + 1 ) + " ) STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int [ ] prufer = { 4 , 1 , 3 , 4 } ; int n = prufer . Length ; printTreeEdges ( prufer , n ) ; } }
Maximum and Minimum in a square matrix . | C # program for finding maximum and minimum in a matrix . ; Finds maximum and minimum in arr [ 0. . n - 1 ] [ 0. . n - 1 ] using pair wise comparisons ; Traverses rows one by one ; Compare elements from beginning and end of current row ; Driver code
using System ; public class GFG { static void maxMin ( int [ , ] arr , int n ) { int min = + 2147483647 ; int max = - 2147483648 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= n / 2 ; j ++ ) { if ( arr [ i , j ] > arr [ i , n - j - 1 ] ) { if ( min > arr [ i , n - j - 1 ] ) min = arr [ i , n - j - 1 ] ; if ( max < arr [ i , j ] ) max = arr [ i , j ] ; } else { if ( min > arr [ i , j ] ) min = arr [ i , j ] ; if ( max < arr [ i , n - j - 1 ] ) max = arr [ i , n - j - 1 ] ; } } } Console . Write ( " Maximum ▁ = ▁ " + max + " , ▁ Minimum ▁ = ▁ " + min ) ; } static public void Main ( ) { int [ , ] arr = { { 5 , 9 , 11 } , { 25 , 0 , 14 } , { 21 , 6 , 4 } } ; maxMin ( arr , 3 ) ; } }
Print matrix in antispiral form | C # Code for Print matrix in antispiral form ; k - starting row index m - ending row index l - starting column index n - ending column index i - iterator ; Print the first row from the remaining rows ; Print the last column from the remaining columns ; Print the last row from the remaining rows ; Print the first column from the remaining columns ; Driver program to test above function
using System ; using System . Collections . Generic ; public class GFG { public static void antiSpiralTraversal ( int m , int n , int [ ] [ ] a ) { int i , k = 0 , l = 0 ; Stack < int > stk = new Stack < int > ( ) ; while ( k <= m && l <= n ) { for ( i = l ; i <= n ; ++ i ) { stk . Push ( a [ k ] [ i ] ) ; } k ++ ; for ( i = k ; i <= m ; ++ i ) { stk . Push ( a [ i ] [ n ] ) ; } n -- ; if ( k <= m ) { for ( i = n ; i >= l ; -- i ) { stk . Push ( a [ m ] [ i ] ) ; } m -- ; } if ( l <= n ) { for ( i = m ; i >= k ; -- i ) { stk . Push ( a [ i ] [ l ] ) ; } l ++ ; } } while ( stk . Count > 0 ) { Console . Write ( stk . Peek ( ) + " ▁ " ) ; stk . Pop ( ) ; } } public static void Main ( string [ ] args ) { int [ ] [ ] mat = new int [ ] [ ] { new int [ ] { 1 , 2 , 3 , 4 , 5 } , new int [ ] { 6 , 7 , 8 , 9 , 10 } , new int [ ] { 11 , 12 , 13 , 14 , 15 } , new int [ ] { 16 , 17 , 18 , 19 , 20 } } ; antiSpiralTraversal ( mat . Length - 1 , mat [ 0 ] . Length - 1 , mat ) ; } }
Minimum operations required to set all elements of binary matrix | C # program to find minimum operations required to set all the element of binary matrix ; Return minimum operation required to make all 1 s . ; check if this cell equals 0 ; increase the number of moves ; flip from this cell to the start point ; flip the cell ; Driven Program
using System ; public class GFG { public const int N = 5 ; public const int M = 5 ; public static int minOperation ( bool [ ] [ ] arr ) { int ans = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { for ( int j = M - 1 ; j >= 0 ; j -- ) { if ( arr [ i ] [ j ] == false ) { ans ++ ; for ( int k = 0 ; k <= i ; k ++ ) { for ( int h = 0 ; h <= j ; h ++ ) { if ( arr [ k ] [ h ] == true ) { arr [ k ] [ h ] = false ; } else { arr [ k ] [ h ] = true ; } } } } } } return ans ; } public static void Main ( string [ ] args ) { bool [ ] [ ] mat = new bool [ ] [ ] { new bool [ ] { false , false , true , true , true } , new bool [ ] { false , false , false , true , true } , new bool [ ] { false , false , false , true , true } , new bool [ ] { true , true , true , true , true } , new bool [ ] { true , true , true , true , true } } ; Console . WriteLine ( minOperation ( mat ) ) ; } }
C Program To Check whether Matrix is Skew Symmetric or not | C # program to check whether given matrix is skew - symmetric or not ; Utility function to create transpose matrix ; Utility function to check skew - symmetric matrix condition ; Utility function to print a matrix ; Driver Code ; Function create transpose matrix ; Check whether matrix is skew - symmetric or not
using System ; class GFG { static int ROW = 3 ; static int COL = 3 ; static void transpose ( int [ , ] transpose_matrix , int [ , ] matrix ) { for ( int i = 0 ; i < ROW ; i ++ ) for ( int j = 0 ; j < COL ; j ++ ) transpose_matrix [ j , i ] = matrix [ i , j ] ; } static bool check ( int [ , ] transpose_matrix , int [ , ] matrix ) { for ( int i = 0 ; i < ROW ; i ++ ) for ( int j = 0 ; j < COL ; j ++ ) if ( matrix [ i , j ] != - transpose_matrix [ i , j ] ) return false ; return true ; } static void printMatrix ( int [ , ] matrix ) { for ( int i = 0 ; i < ROW ; i ++ ) { for ( int j = 0 ; j < COL ; j ++ ) Console . Write ( matrix [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int [ , ] matrix = { { 0 , 5 , - 4 } , { - 5 , 0 , 1 } , { 4 , - 1 , 0 } , } ; int [ , ] transpose_matrix = new int [ ROW , COL ] ; transpose ( transpose_matrix , matrix ) ; Console . WriteLine ( " Transpose ▁ matrix : ▁ " ) ; printMatrix ( transpose_matrix ) ; if ( check ( transpose_matrix , matrix ) ) Console . WriteLine ( " Skew ▁ Symmetric ▁ Matrix " ) ; else Console . WriteLine ( " Not ▁ Skew ▁ Symmetric ▁ Matrix " ) ; } }
Sum of matrix element where each elements is integer division of row and column | C # program to find sum of matrix element where each element is integer division of row and column . ; Return sum of matrix element where each element is division of its corresponding row and column . ; For each column . ; count the number of elements of each column . Initialize to i - 1 because number of zeroes are i - 1. ; For multiply ; Driver Code
using System ; class GFG { static int findSum ( int n ) { int ans = 0 , temp = 0 , num ; for ( int i = 1 ; i <= n && temp < n ; i ++ ) { temp = i - 1 ; num = 1 ; while ( temp < n ) { if ( temp + i <= n ) ans += ( i * num ) ; else ans += ( ( n - temp ) * num ) ; temp += i ; num ++ ; } } return ans ; } public static void Main ( ) { int N = 2 ; Console . WriteLine ( findSum ( N ) ) ; } }
Find number of transformation to make two Matrix Equal | C # program to find number of countOpsation to make two matrix equals ; Update matrix A [ ] [ ] so that only A [ ] [ ] has to be countOpsed ; Check necessary condition for condition for existence of full countOpsation ; If countOpsation is possible calculate total countOpsation ; Driver code
using System ; class GFG { static int countOps ( int [ , ] A , int [ , ] B , int m , int n ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) A [ i , j ] -= B [ i , j ] ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 1 ; j < m ; j ++ ) if ( A [ i , j ] - A [ i , 0 ] - A [ 0 , j ] + A [ 0 , 0 ] != 0 ) return - 1 ; int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) result += Math . Abs ( A [ i , 0 ] ) ; for ( int j = 0 ; j < m ; j ++ ) result += Math . Abs ( A [ 0 , j ] - A [ 0 , 0 ] ) ; return ( result ) ; } public static void Main ( ) { int [ , ] A = { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ; int [ , ] B = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; Console . Write ( countOps ( A , B , 3 , 3 ) ) ; } }