Playing with FFT

When you use integer values, for example 0..1023 with 512 points fft you may use:

f=20; //frequency 
for (i=0; i<512; i++) {
  k[i] = 1023*sin(2*pi*f*i/511);
}

As the result you shall see a frequency in the bin n. 20 with an amplitude of aprox 511 (where in bin n. 0 is DC).
You will see of course some data in other bins as well. That is normal. When sampling real data you have to be aware of aliasing, and you need to apply a "windowing" function before doing the fft (Hamming, Hann(ing), Blackman, and 20 others - in order to eliminate the effect of the sampling window).
By using the windowing function the "shape" of the spectral lines (ie your n.20) changes - you will see less noise around the particular spectral line.

PS: Corrected