struct PTS{
int x,y;
};
double AspectRatio=0.85;
void LineToDemo(void)
{
struct viewporttype vp;
struct PTS points[MAXPTS];
int i,j,h,w,xcenter,ycenter;
int radius,angle,step;
double rads;
printf("MoveTo/LineTo Demonstration");
getviewsettings(&vp);
h=p;
w=vp.right-vp.left;
xcenter=w/2;/*Determine the center of circle*/
ycenter=h/2;
radius=(h-30)/(AspectRatio*2); step=360/MAXPTS;/*Determine#of increments*/
angle=0;/*Begin at zero degrees*/ for(i=0;i<MAXPTS;++i){/*Determine circle intercepts*/
rads=(double)angle*PI/180.0;/* Convert angle to radians*/
points[i].x=xcenter+(int)(cos(rads) *radius);
points[i].y=ycenter-(int)(sin(rads) *radius*AspectRatio);
angle+=step;/*Move to next increment */
}
circle(xcenter,ycenter,radius);/* Draw bounding circle*/
for(i=0;i<MAXPTS;++i){/*Draw the cords to the circle*/
for(j=i;j<MAXPTS;++j){/*For each remaining intersect*/
moveto(points[i].x,points[i].y);/* Move to beginning of cord*/
lineto(points[j].x,points[j].y);/* Draw the cord*/}}}
main()
{int driver,mode;
基础c语言代码driver=CGA;mode=CGAC0;
initgraph(&driver,&mode,"");
setcolor(3);
setbkcolor(GREEN);
LineToDemo();}
===================================== =========================
【程序66】
题目:输入3个数a,b,c,按大小顺序输出。
1.程序分析:利用指针方法。
2.程序源代码:
/*pointer*/
main()
{
int n1,n2,n3;
int*pointer1,*pointer2,*pointer3; printf("please input3 number:n1,n2,n3:");
scanf("%d,%d,%d",&n1,&n2,&n3);
pointer1=&n1;
pointer2=&n2;
pointer3=&n3;
if(n1>n2)swap(pointer1,pointer2);
if(n1>n3)swap(pointer1,pointer3);
if(n2>n3)swap(pointer2,pointer3); printf("the sorted numbers are:%d,%d,%d\n",n1,n2,n3);
}
swap(p1,p2)
int*p1,*p2;
{int p;
p=*p1;*p1=*p2;*p2=p;
}
===================================== =========================
【程序67】
题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
1.程序分析:谭浩强的书中答案有问题。
2.程序源代码:
main()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。