| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 987 人关注过本帖
标题:单摆C语言程序代码
只看楼主 加入收藏
T415022056
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-5-11
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
单摆C语言程序代码
#include<graphics.h>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#define A 480
#define B 120
main()
{
 char q;
 int gdriver=VGA,gmode=VGAHI;
 int i,cl=0,w=1;
 float x,y,v1,v2,a1,a2,L,M,m,k,X,X0,F,F1,F2,g,c,s,G,G1,G2;
 float sp=2;
 initgraph(&gdriver,&gmode,"");
BG: cleardevice();
 setcolor(5);
 setbkcolor(0);
 settextstyle(3,0,4);
 outtextxy(80,50,"Single Pendulum Parameters Input");
 setcolor(1);
 rectangle(70,50,600,90);
        setcolor(2);
 rectangle(65,45,605,95);
 setcolor(14);
 rectangle(60,40,610,100);
 setcolor(5);
 moveto(100,100);
 gotoxy(49,12);printf("");
 settextstyle(1,0,2);
 outtextxy(80,130,"PLEASE INPUT :  ( 0<L<120 )");
 setcolor(15);
 line(50,160,620,160);
 setcolor(5);
 outtextxy(80,170,"The Length Of Pendulum L : ");
 scanf("%f",&L);
 gotoxy(35,15);printf("");
 settextstyle(1,0,2);
 outtextxy(80,205,"Elastic Coefficient k : ");
 gotoxy(40,14);printf("");
 scanf("%f",&k);
 outtextxy(80,250,"The Quality Of Spherule  M :");
 gotoxy(50,17);printf("");
 scanf("%f",&M);
 outtextxy(80,297,"The Quality Of Pedulum Line  m : ");
 gotoxy(58,20);printf("");
 scanf("%f",&m);
 setcolor(15);
 line(50,380,620,380);
 setcolor(5);
 outtextxy(60,400,"Press E to Quit AND Press Any Other Key to Go on");
 q=getch();
 if(q=='e'||q=='E') goto END;
 cleardevice();
GN: setcolor(2);
                setbkcolor(0);
                g=9.8;G=m*g;x=A+L;y=B;v1=0;v2=0;
 settextstyle(1,0,3);
 outtextxy(380,20,"Single Pendulum");
 settextstyle(1,0,1);
 outtextxy(390,60,"(with a spherule)");
 settextstyle(1,0,3);
 outtextxy(20,40,"S-Pendulum Parameters :");
 settextstyle(1,0,1);
 moveto(100,90);
 gotoxy(29,7);printf("%.1f",L);
 outtextxy(30,90,"Length of line  L :");
 gotoxy(30,9);printf("%.2f",k);
 outtextxy(30,123,"P-Coefficient  k :");
 gotoxy(30,11);printf("%.2f",M);
 outtextxy(30,156,"Spherule Quality M :");
 gotoxy(30,13);printf("%.2f",m);
 outtextxy(30,189,"Line Quality m :");
 gotoxy(32,15);printf("%d",w);
 outtextxy(30,222,"Control Increment w : ");
 settextstyle(2,0,6);
 outtextxy(25,290,"Exegesis :");
 settextstyle(2,0,4);
 outtextxy(30,320,"  Demo Speed : A -- accelerate , S -- decelerate");
 outtextxy(30,340,"   SP-Length : - -- decrease   , + -- increase  ");
 outtextxy(30,360," Coefficient : < -- decrease   , > -- increase  ");
 outtextxy(30,380," Sph-Quality : Z -- decrease   , X -- increase  ");
 outtextxy(30,400,"Line-Quality : C -- decrease   , V -- increase  ");
 outtextxy(30,420,"   Increment : Q -- decrease   , W -- increase  ");
 outtextxy(30,440," Press R to Reload AND Press E to Quit");
 rectangle(20,285,320,460);
 do
 {
   for(i=0;i<1;i++)
   {
    setcolor(cl++);
    cl %= 16;
    for(i=0;i<180;i=i+5)
    {
     arc(A,B,180+i,i+182,L);
    }
    setcolor(0);
 
line(x,y,A,B);
                setcolor(11);
                circle(x,y,1);
                X0=sqrt((x-A)*(x-A)+(y-B)*(y-B));
                X=X0-L;
                c=(x-A)/X0;
                s=(y-B)/X0;
                G1=G*c;
                G2=G*s;
                F=k*X;
                F1=-F*c;
                F2=M*g-F*s-G2*s+G1*c;
a1=F1/M;
                a2=F2/M;
                v1=v1+a1;
                v2=v2+a2;
                x=x+v1;
                y=y+v2;
                setcolor(1);
                circle(x,y,1);
                setcolor(14);
                line(x,y,A,B);
                for(i=1;i<sp;i++)
{
                    delay(1000);
                          }
 
 
 
                         }
 }
 while(!kbhit()==1);
                 q=getch();
 cleardevice();
 if(q=='e'||q=='E') goto END;
                  if(q=='r'||q=='R') goto BG;
                  if(q=='s'||q=='s') sp=sp+1;
if(q=='a'||q=='A') sp=sp-1;
 if(q=='-'||q=='_') L=L-1*w;
 if(q=='='||q=='+') L=L+1*w;
                  if(q==','||q=='<') k=k-0.1*w;
 if(q=='.'||q=='>') k=k+0.1*w;
                  if(q=='z'||q=='Z') M=M-0.1*w;
 if(q=='x'||q=='X') M=M+0.1*w;
 if(q=='c'||q=='C') m=m-0.1*w;
                  if(q=='v'||q=='V') m=m+0.1*w;
                  if(q=='w'||q=='W') w=w+1;
 if(q=='q'||q=='Q') w=w-1;
                  goto GN;
 
 
END: closegraph();
}
请问这个怎么运行不了啊,请帮助我!谢谢tc2.0
搜索更多相关主题的帖子: include C语言 
2013-05-11 22:16
sprout_小鱼
Rank: 1
等 级:新手上路
帖 子:1
专家分:7
注 册:2013-5-12
收藏
得分:7 
新手看不懂
2013-05-12 00:34
Agdmeg
Rank: 4
来 自:四川成都
等 级:业余侠客
威 望:3
帖 子:101
专家分:201
注 册:2011-8-9
收藏
得分:7 
在初始化图形函数加入路径TC表示编译测试成功initgraph(&gdriver,&gmode,"C:\\TC20H");
2013-05-12 01:19
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:7 
TC中可以用这个图形头文件#include<graphics.h>
VC不支持,

Maybe
2013-05-12 10:56
快速回复:单摆C语言程序代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017246 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved