View Code of Problem 106

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
	float x1,x2,y1,y2,r;
	while(scanf("%f%f%f%f%f",&x1,&y1,&x2,&y2,&r)!=EOF)
	{
		float d=sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1)),a,s;
		if(d==0) printf("重合\n");
		if(d==2*r) printf("相切\n");
		if(d>2*r) printf("相离\n");
		if(d<2*r&&d>0) 
		{
			a= acos(d/(2*r));    
			s= 2*r*r*a-d*r*sin(a);
			printf("相交 %.2f\n",s);
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 106