写一个检测直线的c语言程序
以下是一个检测直线的C语言程序,它可以检测给定的两个点是否在同一条直线上:
#include <stdio.h>
int main() { int x1, y1, x2, y2; printf("Enter the coordinates of the first point: "); scanf("%d %d", &x1, &y1); printf("Enter the coordinates of the second point: "); scanf("%d %d", &x2, &y2); if ((y2 - y1) * (x2 - x1) == (y2 - y1) * (x2 - x1)) { printf("The two points are on the same line.\n"); } else { printf("The two points are not on the same line.\n"); } return 0; }
在上面的程序中,我们首先使用scanf函数从用户那里获取两个点的坐标。然后我们使用一个简单的公式来检查这两个点是否在同一条直线上。如果公式成立,我们输出一条消息,表示这两个点在同一条直线上。否则,我们输出另一条消息,表示这两个点不在同一条直线上
原文地址: https://www.cveoy.top/t/topic/cg3d 著作权归作者所有。请勿转载和采集!