用C++写一个判断两条直线角度
时间: 2023-12-27 14:57:40 浏览: 35
#include <stdio.h>
#include <math.h>
int main() {
float x1, y1, x2, y2, x3, y3, x4, y4, k1, k2, angle;
printf("Enter the coordinates of the first point on the first line (x1, y1): ");
scanf("%f %f", &x1, &y1);
printf("Enter the coordinates of the second point on the first line (x2, y2): ");
scanf("%f %f", &x2, &y2);
printf("Enter the coordinates of the first point on the second line (x3, y3): ");
scanf("%f %f", &x3, &y3);
printf("Enter the coordinates of the second point on the second line (x4, y4): ");
scanf("%f %f", &x4, &y4);
// Calculate the slopes of the lines
k1 = (y2 - y1) / (x2 - x1);
k2 = (y4 - y3) / (x4 - x3);
// Calculate the angle between the lines in degrees
angle = fabs(atan((k2 - k1) / (1 + k1 * k2)) * 180 / M_PI);
printf("The angle between the lines is %.2f degrees.\n", angle);
return 0;
}