sum will temporarily store the sum of cosine signals
sum = 0 ; for ( k = 0 ; k < m ; k ++ ) { for ( l = 0 ; l < n ; l ++ ) { dct1 = matrix [ k ] [ l ] * cos ( ( 2 * k + 1 ) * i * pi / ( 2 * m ) ) * cos ( ( 2 * l + 1 ) * j * pi / ( 2 * n ) ) ; sum = sum + dct1 ; } } dct [ i ] [ j ] = ci * cj * sum ; } } for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { printf ( " % f TABSYMBOL " , dct [ i ] [ j ] ) ; } printf ( " STRNEWLINE " ) ; } }