Count frequency of k in a matrix of size n where matrix ( i , j ) = i + j | C # program to find the frequency of k in matrix in matrix where m ( i , j ) = i + j ; Driver function
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 ) ; } }