以下のC言語のプログラムをpythonで書くとどうなりますか? 至急お願いします! #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { double t, ts[10000], x, xs[10000]; int n = 0; FILE *fp; fp = fopen("data.txt", "r"); while (fscanf(fp, "%lf %lf", &t, &x) != EOF) { ts[n] = t; xs[n] = x; n++; } fclose(fp); printf("%d data are read.¥n", n); fp = fopen("out.txt", "w"); double h = ts[1] - ts[0]; double w; for (w = 0.0; w < 10.0; w += 0.01) { double Re = 0; double Im = 0; int i; for (i = 0; i < n; i++) { Re += xs[i] * cos(w * ts[i]) * h; Im += xs[i] * sin(w * ts[i]) * h; } double F = sqrt(Re * Re + Im * Im); fprintf(fp, "%lf %lf¥n", w, F); } fclose(fp); return 0; }
プログラミング