怎样用C++语言(Turbo C)绘制任意正多边形?我需要源程序
2011-12-27
展开全部
这是一个画正多边形的代码,希望对你有帮助:
#include"graphics.h"
#include<math.h>
#include<stdio.h>
#include<conio.h>
void polygon(int x0,int y0,int a,int n,float af)
{
int x,y,i;
double dtheta,theta;
if(n<3)
return;
dtheta=6.28318/n;
theta=af*0.0174533;
moveto(x0,y0);x=x0;y=y0;
for(i=1;i<n;i++)
{
x=x+a*cos(theta);y=y+a*sin(theta);
lineto(x,y);theta=theta+dtheta;
}
lineto(x0,y0);
}
void main()
{
int i,a=80,x=200,y=100;
int gdriver=DETECT,gmode;
printf("请输入边数:");
scanf("%d",&i);
if (i<3)
{
printf("边数不够");
}
initgraph(&gdriver,&gmode,"d:\\tc");
cleardevice();
setbkcolor(9);setcolor(GREEN);
polygon(x,y,a,i,0.);
getch();
closegraph();
}
#include"graphics.h"
#include<math.h>
#include<stdio.h>
#include<conio.h>
void polygon(int x0,int y0,int a,int n,float af)
{
int x,y,i;
double dtheta,theta;
if(n<3)
return;
dtheta=6.28318/n;
theta=af*0.0174533;
moveto(x0,y0);x=x0;y=y0;
for(i=1;i<n;i++)
{
x=x+a*cos(theta);y=y+a*sin(theta);
lineto(x,y);theta=theta+dtheta;
}
lineto(x0,y0);
}
void main()
{
int i,a=80,x=200,y=100;
int gdriver=DETECT,gmode;
printf("请输入边数:");
scanf("%d",&i);
if (i<3)
{
printf("边数不够");
}
initgraph(&gdriver,&gmode,"d:\\tc");
cleardevice();
setbkcolor(9);setcolor(GREEN);
polygon(x,y,a,i,0.);
getch();
closegraph();
}
更多追问追答
追问
c:\documents and settings\administrator\c.cpp(1) : fatal error C1083: Cannot open include file: 'graphics.h': No such file or directory
执行 cl.exe 时出错
有一个错误,你能修改一下吗?
追答
不是吧,你使用的是TC吗?TC肯定包含'graphics.h'的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询