回复 楼主 闫安
#include<stdio.h>
#include<math.h>
struct Ellipse
{
short x1;
short y1;
short x2;
short y2;
short span;
};
int main()
{
short right,bottom,i,idx;
struct Ellipse myEllipse;
printf("输入焦点1坐标,用逗号隔开:");
scanf("%d,%d",&myEllipse.x1,&myEllipse.y1);
printf("输入焦点2坐标,用逗号隔开:");
scanf("%d,%d",&myEllipse.x2,&myEllipse.y2);
do
{
printf("输入椭圆上的点离两个焦点的距离之和(应大于两个焦点间的距离):");
scanf("%d",&myEllipse.span);
}while(myEllipse.span<=sqrt((myEllipse.x1-myEllipse.x2)*(myEllipse.x1-myEllipse.x2)+(myEllipse.y1-myEllipse.y2)*(myEllipse.y1-myEllipse.y2)));
right=myEllipse.span+myEllipse.x1;bottom=myEllipse.span+myEllipse.y1;
for(i=0;i<=right;i++)
{
for(idx=0;idx<=bottom;idx++)
{
if((short)(sqrt((idx-myEllipse.x1)*(idx-myEllipse.x1)+(i-myEllipse.y1)*(i-myEllipse.y1))+sqrt((idx-myEllipse.x2)*(idx-myEllipse.x2)+(i-myEllipse.y2)*(i-myEllipse.y2)))==myEllipse.span)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
//随便瞎弄了一个,不知道是不是这个意思。