当前位置:首页 > 周期矩形波周期锯齿波周期三角波 C语言程序
周期三角波C语言代码 #include
double function(double t); double sum();double draw(); double function(double t) {
double x,s,w,m; int n; w=2*pi/T1; s=0;
for(n=1;n<=200;n++) {
x=cos((2*n-1)*w*t)/((2*n-1)*(2*n-1)); s=x+s;
}
m=s*4*E/(pi*pi)+E/2; return(m); }
void check_initialize() {
int driver,mode;
detectgraph(&driver,&mode);
initgraph(&driver,&mode,\double sum() {
double c,t,m,x[301],s[300]; int i,g,y,j; x[0]=0;
for(i=1;i<=200;i++) { setcolor(5); x[i]=x[i-1]+0.02; c=x[i];
s[i]=function(c);
line(100*x[i-1]+20,-100*s[i-1]+400,100*x[i]+20,-100*s[i]+400);
} return 0; }
double draw() {
int l,b[61],c[60]; b[0]=200; setcolor(9);
line(10,400,600,400); line(20,410,20,30); setcolor(6); line(15,35,20,30); line(25,35,20,30); line(595,395,600,400); line(595,405,600,400); for(l=1;l<=50;l++) {
b[l]=b[l-1]+4; c[l]=220;
putpixel(c[l],b[l],5); }
outtextxy(10,25,\ outtextxy(605,405,\ outtextxy(220,400,\ outtextxy(10,200,\ outtextxy(10,400,\ return 0; }
void main() {
check_initialize(); setbkcolor(15); sum(); draw(); getch(); }
共分享92篇相关文档