diff --git a/5_practice.c b/5_practice.c index 70d6651..6d2e52e 100644 --- a/5_practice.c +++ b/5_practice.c @@ -9,31 +9,60 @@ int main() { time_t t; // Input the number N - + printf("Please input a number N\n"); + scanf("%d",&N); // Locate the memory for x, yr, yi; - + x = (double *)malloc(N * sizeof(double)); + yr = (double *)malloc(N * sizeof(double)); + yi = (double *)malloc(N * sizeof(double)); // Initial setting for x, for example, x[k] = k - - + for (k=0;k 1) + printf("\n "); + printf(" %.0f ", x[k]); + } + printf(" )\n"); + + printf("F(x) = \n"); + printf("( "); + for (n = 0; n < N; n++) + { + if (n % 5 == 0 && n > 1) + printf("\n "); + printf(" %.2f %+.2fi ", yr[n], yi[n]); + } + printf(" )\n"); + printf("%d ms for discrete Fourier Transform of %d elements\n", t, N); // free the memory located by x, yr, yi - - + free(x); + free(yr); + free(yi); return 100; }