叫 AUTOCAD 自動畫 SIN 函數圖形的 C 語言程式設計
(高顯忠, sjgau4311@gmail.com, 2010-11-29 17:22)
1樓
#include "stdio.h"
#include "math.h"
int main()
{
FILE *f1;
f1= fopen("plot-sin.scr", "wt");
// plot y= sin(x), x= x1 to x2 step dx
int no= 16;// 16 個等分
double x1, x2, dx, x, y;
x1= 0.0;
x2= 4.0*atan(1.0);// x2= 3.1415926
dx= (x2 - x1)/no;
x2= x2 + (dx/10.0);
// for x= x1 to x2 step dx do ...
fprintf(f1, "spline\n");
for (x= x1;x <= x2;x+= dx) {
y= sin(x);
fprintf(f1, "%.6lf,%.6lf\n", x, y);
}
fprintf(f1, "\n\n\n");
fclose(f1);
return(0);
}// end of main()