Find the element in the matrix generated by given rules | 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
function getElement ( N , r , c ) { if ( r > c ) return 0 ; if ( r == 1 ) { return c ; } let a = ( r + 1 ) * parseInt ( Math . pow ( 2 , ( r - 2 ) ) ) ; let d = parseInt ( Math . pow ( 2 , ( r - 1 ) ) ) ; c = c - r ; let element = a + d * c ; return element ; } let N = 4 , R = 3 , C = 4 ; document . write ( getElement ( N , R , C ) ) ;