题目来源:码蹄集
https://matiji.net/exam/brushquestion/593/778/B3FCFEC101BD05189BB74D522E019504
参考程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef struct tagPOINT { //点
int x, y; //坐标值x和y
} POINT;
typedef struct tagLINE { //线
POINT s, e; //线的两端
} LINE;
int main()
{
POINT p;
LINE line;
float d;
scanf("%d %d", &line.s.x, &line.s.y);
scanf("%d %d", &line.e.x, &line.e.y);
scanf("%d %d", &p.x, &p.y);
d = (line.s.y - line.e.y)*p.x + (line.e.x - line.s.x)*p.y + (line.s.x*line.e.y - line.e.x*line.s.y);
d = fabs(d) / sqrt((line.e.x - line.s.x)*(line.e.x - line.s.x) + (line.e.y - line.s.y)*(line.e.y - line.s.y));
d = floor(d);
printf("%d\n", (int)(d));
return 0;
}