一道c语言编程题目 请编写一个程序实现:判断平面上的某个点是否在某个圆的内部。要求如下: 1)定

2024-12-05 00:53:35
推荐回答(2个)
回答1:

#include

typedef struct PP

{double x,y;}POINT;


typedef struct CC

{POINT O;

 double r;}CIRCLE;


int incircle(POINT p,CIRCLE c1)

{return ((p.x-c1.O.x)*(p.x-c1.O.x)+(p.y-c1.O.y)*(p.y-c1.O.y)<=c1.r*c1.r);}


int main()

{POINT p1,p2;

 CIRCLE C;

p1.x=1.0;

p1.y=1.0;

p2.x=-1.0;

p2.y=2.0;

C.O.x=0;

C.O.y=0;

C.r=2.0;

printf("%d\n",incircle(p1,C));

printf("%d\n",incircle(p2,C));

return 0;

}

回答2:

这个简单,随手写的,未编译,未验证,仅供参考

#include "stdio.h"
#include "math.h"
typedef struct _POINT
{
int x ;
int y ;
}POINT , *PPOINT ;

typedef struct _CIRCLE
{
int x ;
int y ;
float r ;
}CIRCLE , *PCIRCLE ;

int incircle( PPOINT p , PCIRCLE c )
{
float a , b , m ;
a =fabs( (float)p ->x - (float) c ->x ) ;
b =fabs( (float)p ->y - (float) c ->y ) ;
m = (float)sqrt( a * a + b * b ) ;
return ( m <= c ->r ? 1: 0 ) ;
}