You have to read this sentence again
:

Originally Posted by
Wikipedia
Formal definition
Formally, the discrete cosine transform is a linear, invertible function F : RN -> RN (where R denotes the set of real numbers), or equivalently an N × N square matrix. There are several variants of the DCT with slightly modified definitions. The N real numbers x0, ..., xN-1 are transformed into the N real numbers X0, ..., XN-1 according to one of the formulas:
So your original 8-element array x determines the values of your new 8-element array X. Make sure the variables are different, you don't want to overwrite the original values of x, or you won't compute it correctly.
Therefore k will also be 0..7.
And you want:
Code:
for(int k=0;k<8;k++)
{
xnew[k]=0;
for(int n=0;n<8;n++)
{
xnew[k] += X[n] * cos((PI/8)*(n+.5)*k);
}
}