View Code of Problem 106

# include <stdio.h>
# include <math.h>
 
int main(void)
{
	double x1 , y1 , x2 , y2 ,r;
	double d , c ,s;     //圆心之间的距离 
	while(scanf("%lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&r)!=EOF)
	{
		d = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
		if(d == 2*r)
			printf("相切\n");
		else if (d > 2*r)
			printf("相离\n");
		else if (d == 0) 
			printf("重合\n");
		else
		{
			printf("相交 ");	
			c=acos(d/2.0/r);
			s=c*r*r-d/2.0*r*sin(c);
			printf("%.2lf\n",2*s);
		}	
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 106