输入两个点输出一条过点的直线 c语言编程

2025-01-02 03:44:04
推荐回答(1个)
回答1:

#include
#include

int main()
{
float x1,y1,x2,y2;
scanf("%f%f%f%f",&x1,&y1,&x2,&y2);
if(x1==x2&&y1==y2)
{
printf("error\n");
}
else if(x1==x2)
{
printf("y=%d\n",x1);
}
else if(y1==y2)
{
printf("x=%d\n",y1);
}
else
{
printf("y=%fx+%f\n",(y2-y1)/(x2-x1),y2-(y2-y1)/(x2-x1)*x1);
}
system("pause");
return 0;
}