2016福州马拉松成绩:急,明天要交了

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 06:19:28
合振动的C语言模拟,要求作图

#include <dos.h>
#include <conio.h>
#define A(k,x,r,p) k*(x/10-p)/pow(r,3)
main()
{

int graphdrv = DETECT, graphmode, errorcode;
int i;
float k=0.75,dt=0.05,x0,y0,x,y,vx,vy,ax,ay,r;
time_t t;
srand((unsigned)time(&t));
initgraph(&graphdrv,&graphmode,"F:\\borlandc\\BGI");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
line(400,0,400,480);
line(0,240,640,240);
fillellipse(400,240,20,20);
settextstyle(1,0,0);
outtextxy(180,0,"SCATTERED");
outtextxy(180,25,"ALPHA RAY");
settextstyle(3,0,0);
outtextxy(440,210,"Scattering");
outtextxy(460,235,"Nuclear");
vx=1.5+random(250)/100.0;
for(i=0;i<5;i++)
{
y0=130+25*i;
y=y0;
x=x0=2;
vy=0;
r=sqrt(pow(x/10-40,2)+pow(y/10-24,2));
ax=A(k,x,r,40);
ay=A(k,y,r,24);
vx=vx+0.5*ax*dt;
vy=vy+0.5*ay*dt;
while(1){
delay(1);
x=x+vx*dt;
y=y+vy*dt;
r=sqrt(pow(x/10-40,2)+pow(y/10-24,2));
ax=A(k,x,r,40);
ay=A(k,y,r,24);
vx=vx+ax*dt;
vy=vy+ay*dt;
if(x>639)
break;
if(x<2)
break;
if(y<2)
break;
line(x0,y0,x,y);
line(x0,480-y0,x,480-y);
x0=x;
y0=y;
}
continue;

}
while(!kbhit());
closegraph();
}