Find the element at R ' th ▁ row ▁ and ▁ C ' th column in given a 2D pattern | C ++ implementation to compute the R ' th ▁ row ▁ and ▁ C ' th column of the given pattern ; Function to compute the R ' th ▁ row ▁ and ▁ C ' th column of the given pattern ; First element of a given row ; Element in the given column ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findValue ( int R , int C ) { int k = ( R * ( R - 1 ) ) / 2 + 1 ; int diff = R + 1 ; for ( int i = 1 ; i < C ; i ++ ) { k = ( k + diff ) ; diff ++ ; } return k ; } int main ( ) { int R = 4 ; int C = 4 ; int k = findValue ( R , C ) ; cout << k ; return 0 ; }