What is going wrong with my IDFT program?
I suspect reason is that my IDFT program takes into account every leakage frequency.

Also in complex numbers multiplication I do not take into account imaginary unit.

I apologize for the errors.

My answer to my question is the following C++ program. It performs DFT and IDFT on 20 input values in array, and outputs the same values. Sample rate for calculate input signal from existing sinusoids is 71114 Hz, and N = 20. Existing sinusoids are two:

1. Amplitude = 995,574, frequency = 20247 Hz, phase = 0.34 π.
2.    "      = 492,356      "     = 3818 Hz,    "   = 0.15 π.


Sample rate for DFT and IDFT is 45940 Hz, and N = 20. I point out that existing frequencies are not multiples of sample rate by N. So, there is leakage but is not problem. Any one can change values. These in program are random in limits. Any one can use first program in my question, for calculate input x(n) from any sinusoids.

     #include &lt;iostream&gt;
     #include "math.h"

     int main()
     {
     //Unchanged variables.
     float pi = 3.141592653589793; //pure number.
     int n = 0; // sample.
     float Re = 0; //pure number.
     float Im = 0; //pure number.
     float xn_cos = 0; //pure number.
     float xn_sin = 0; //pure number.
     float cosine = 0;
     float sine = 0;
     float sumReal = 0;
     float real = 0;
    int m = 0;
    int no = 0;

    //Sampling frequency and samples of segment.
    int samplFreq = 45940; // sample/second.
    int N = 20; //sample. Number of input samples.

   // Testing grid.
    float testFreq = 0; // Hz.
    float testUnitAngle = 0; // rad/sample.
    float testAngle = 0; // rad.
    float lowTestFreq = 0; //Hz.
    float highTestFreq = samplFreq; //Hz.
    int M = N; // pure number. Number of DFT output samples.
    float testFreqStep = (highTestFreq - lowTestFreq) / M; // Hz.
    float xn[] =
{ 1.09595e+06,
 635609,
-544799,
 640870,
 1.40537e+06,
-142213,
-392826,
 1.00018e+06,
 307386,
-1.16555e+06,
-211430,
 518555,
-998272,
-1.20759e+06,
 390434,
 26244.3,
-1.18203e+06,
 25149,
 1.08298e+06,
-200068,};
   int No = N; // pure number. Number of IDFT output samples.

  // IDFT including DFT.
  for (no = 0; no &lt;= No - 1; no++)
    {
            sumReal = 0;
            for (m = 0; m &lt;= M - 1; ++m)
            {
                    testFreq = lowTestFreq + m * testFreqStep; // Hz.
                    testUnitAngle = (testFreq / samplFreq) * (2 * pi); // rad/sample.

                    Re = 0; Im = 0;

                    // Start DFT.
                   for (n = 0; n &lt;= N - 1; ++n)
                    {
                            testAngle = n * testUnitAngle;

                            xn_cos = xn[n] * cos(testAngle);
                            xn_sin = xn[n] * -sin(testAngle); 

                            Re += xn_cos;
                            Im += xn_sin;
                    }
                   // End DFT.

                   cosine = cos(((no * 2 * pi) / N) * m);
                    sine = sin(((no * 2 * pi) / N) * m);
                    real = Re * cosine - Im * sine; // Product of complex
//numbers (Re, Im i) * (cosine, sine i) = (Re * cosine + Re * sine i + Im i *
//cosine + Im i * sine i) = (Re * cosine + Re * sine i + Im i * cosine - Im *
//sine), for, by definition, i * i = -1. Then, first and last product in
//parenthesis are real numbers. Other two are imaginary and their sum is
//practically zero. For the values in array are between -26 and 25.
//More over because  input values are real, output should be real.
                    sumReal += real;
            }
            std::cout &lt;&lt; sumReal / N &lt;&lt; "\n";
    }
    return 0;


}