text: Find the element in the matrix generated by given rules | C # implementation of the above approach ; Function to return the element in the rth row and cth column from the required matrix ; Condition for lower half of matrix ; Condition if element is in first row ; Starting element of AP in row r ; Common difference of AP in row r ; Position of element to find in AP in row r ; Driver Code
code: using System ; class GFG { static int getElement ( int N , int r , int c ) { if ( r > c ) return 0 ; if ( r == 1 ) { return c ; } int a = ( r + 1 ) * ( int ) ( Math . Pow ( 2 , ( r - 2 ) ) ) ; int d = ( int ) ( Math . Pow ( 2 , ( r - 1 ) ) ) ; c = c - r ; int element = a + d * c ; return element ; } public static void Main ( String [ ] args ) { int N = 4 , R = 3 , C = 4 ; Console . WriteLine ( getElement ( N , R , C ) ) ; } }