举报
winner3120
不好意思,第一遍没看好题意: #include #include #define EQUAL(x, y) (fabs((x) - (y)) <= 1e-6) int main() { double k1, b1, k2, b2; //直线1和2的参数k,b,直线为 y = kx + b,其中直线2的参数待定 double tmpx, tmpy; //第一条直线的一点,如题 double x1, y1, x2, y2; //直线2的两点坐标,如题 double resultx, resulty; //焦点的坐标 //输入k,和一点的坐标x,y,以空格为分隔符 printf("Input the k and x, y cand of the point (separate with space): "); scanf("%llf %llf %llf", &k1, &tmpx, &tmpy); b1 = tmpy - k1 * tmpx; //计算直线1参数b printf("Input the first point's x and y cand: "); //输入直线2的第一点 scanf("%llf %llf", &x1, &y1); printf("Input the first point's x and y cand: "); //输入直线2的第二点 scanf("%llf %llf", &x2, &y2); if (EQUAL(x1, x2)) //若x1和x2相等,也就是说直线2没有斜率的情况 { printf("The point is (%.2llf, %.2llf).n", x1, x1 * k1 + b1); } else { //计算直线2的参数 k2 = (y1 - y2) / (x1 - x2); b2 = (y1 * x2 - x1 * y2) / (x2 - x1); if (EQUAL(k2, k1)) //若斜率相同则要么2直线平行要么2直线重合 { if (EQUAL(b2, b1)) //重合 printf("Two lines overlap!n"); else //平行 printf("None point!n"); } else { //解直线方程 resultx = (b1 - b2) / (k2 - k1); resulty = k1 * resultx + b1; printf("The point is (%.2llf, %.2llf).n", resultx, resulty); } } return 0; }