求一个C语言代码,两点连成的直线上某一点的某一点的坐标
发布网友
发布时间:2023-10-29 03:21
我来回答
共2个回答
热心网友
时间:2023-11-11 20:26
#include <stdio.h>
int main() {
double x0, y0, x1, y1;
double a, b, c;
double x;
printf("x0 = ");
scanf("%lf", &x0);
printf("y0 = ");
scanf("%lf", &y0);
printf("x1 = ");
scanf("%lf", &x1);
printf("y1 = ");
scanf("%lf", &y1);
printf("\n\n");
b = x1 - x0;
a = y0 - y1;
c = x0 * y1 - x1 * y0;
a /= b;
c /= b;
while (1) {
printf("x = ");
scanf("%lf", &x);
printf("y = %lf\n\n", -c - a * x);
}
}
热心网友
时间:2023-11-11 20:27
//虽然已经有人给出了我还是贴一下吧,有啥问题欢迎追问
#include<stdio.h>
void main()
{
float x,x1,x2,y1,y2,k,b;
printf("输入第一个点的坐标:\n");
scanf("%f,%f",&x1,&y1);
printf("输入第二个点的坐标:\n");
scanf("%f,%f",&x2,&y2);
k=(y2-y1)/(x2-x1);
b=y1-(k*x1);
while(1)
{
printf("请输入x坐标\n");
scanf("%f",&x);
printf("%f\n",k*x+b);
}
}