怎么用C语言作抛物线,急!!!!!!!

怎么用C语言作抛物线,急!!!!!!!,第1张

/*这是一个画抛物线的程序*/

#include<graphics.h>

#define BKC 9

#define COLOR 8 /* 抛物线颜色*/

#define G 9.856

main()

{int gd=DETECT,gm,p=1,i

double Vx,Vy,x,y,x1,y1,t

char ch

initgraph(&gd,&gm,"")

while(p==1)/*主循环体*/

{

setbkcolor(BKC)

setcolor(14)

setlinestyle(0,0,1)

rectangle(0,0,639,479) /*画边框*/

line(20,460,639,460) /*画横坐标*/

line(20,0,20,460) /*画纵坐标*/

outtextxy(8,467,"0")

setlinestyle(1,0,1)

setcolor(15)

for(i=20i<640i+=20)line(i,460,i,0)

for(i=460i>0i-=20)line(20,i,640,i)

gotoxy(1,1)

printf("Please Enter Vx:" )

scanf("%lf",&Vx)

printf("Please Enter Vy:")

scanf("%lf",&Vy)

for(t=0.0t+=0.00002)

{

x=Vx*t

y=Vy*t-0.5*G*t*t

x1=2*x+20 /*画笔定位在用户坐标原点 (20,460) */

y1=460-y*2

if(y1>460.0||x1>640.0) break

putpixel(x1,y1,COLOR)

}

setcolor(12)

outtextxy(250,8,"Finished! Continue(Y/N)?")

p=-1

while(p==-1)

{

ch=getch()

if(ch=='y'||ch=='Y') { cleardevice()p=1}

else if(ch=='n'||ch=='N') p=0

else outtextxy(220,200,"ERROR! Please Press 'Y' or 'N'_" )

}

}

closegraph()

}

void main()

{

double a,b,c

double x1,y1,x2,x3,y2,y3

double m

printf("please input 3 points:\n")

printf("(x1,y1),(x2,y2),(x3,y3):\n")

scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)

m = x1*x1*x2+x2*x2*x3+x1*x3*x3-x3*x3*x2-x2*x2*x1-x1*x1*x3

printf("////////////////////////////////////////////////\n")

if((m+1)==1)

{

printf("No result with this 3 points!\n")

}

else

{

a=(y1*x2+y2*x3+y3*x1-y3*x2-y2*x1-y1*x3) /m

b=(x1*x1*y2+x2*x2*y3+x3*x3*y1-x3*x3*y2-x2*x2*y1-x1*x1*y3)/m

c=(x1*x1*x2*y3+x2*x2*x3*y1+x3*x3*x1*y2-x3*x3*x2*y1-x2*x2*x1*y3-x1*x1*x3*y2)/m

printf("y = ax^2 + bx + c\n(a=%lf,b=%lf,c=%lf)\n",a,b,c)

}

printf("press any key to quit:\n")

getch()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7689216.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-08
下一篇 2023-04-08

发表评论

登录后才能评论

评论列表(0条)

保存