C语言程序设计100个经典例?- 百度文库 ر

#include \ #define maxpts 15

#define pi struct pts { int x,y; };

double aspectratio=; void linetodemo(void)

{

struct viewporttype vp; struct pts points[maxpts]; int i, j, h, w, xcenter, ycenter;

int radius, angle, step;

double rads;

printf(\

getviewsettings( &vp );

h = - ; w = - ;

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 ; irads = (double)angle * pi / ; /* 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 ; ifor( j=i ; jmoveto(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; driver=cga;mode=cgac0; initgraph(&driver,&mode,\

setcolor(3); setbkcolor(green); linetodemo();}

==============================================================

66

Ŀ3a,b,cС˳

1.ָ뷽

2.Դ룺 /*pointer*/ main() {

int n1,n2,n3;

int *pointer1,*pointer2,*pointer3; printf(\

scanf(\

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(\

} swap(p1,p2) int *p1,*p2; {int p;

p=*p1;*p1=*p2;*p2=p;

}

==============================================================

67

Ŀ飬һԪؽСһԪؽ

1.̷ǿд⡣

2.Դ룺

main()

{

int number[10]; input(number); max_min(number); output(number);

} input(number) int number[10];

{int i; for(i=0;i<9;i++) scanf(\ scanf(\

}

max_min(array) int array[10]; {int *max,*min,k,l; int *p,*arr_end; arr_end=array+10; max=min=array;

for(p=array+1;p if(*p>*max) max=p;

else if(*p<*min) min=p;

k=*max; l=*min;

*p=array[0];array[0]=l;l=*p;