-
Notifications
You must be signed in to change notification settings - Fork 1
/
lines.c
72 lines (64 loc) · 1.81 KB
/
lines.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// CS1010 AY2015/6 Semester 2 PE1 Ex1
//
// line.c
//
// Name:
// Matriculation number:
// plab-id:
// Discussion group:
// Description:
double computeK(double,double,double,double);
int determineType(double, double, double);
void printMessage(int);
#include <stdio.h>
int main(void) {
int Ax,Ay,Bx,By,Cx,Cy,Dx,Dy;
double slopeAB,slopeCD,slopeAC,value;
printf("Enter the coordinates of A: ");
scanf("%d %d", &Ax,&Ay);
printf("Enter the coordinates of B: ");
scanf("%d %d", &Bx,&By);
printf("Enter the coordinates of C: ");
scanf("%d %d", &Cx,&Cy);
printf("Enter the coordinates of D: ");
scanf("%d %d", &Dx,&Dy);
slopeAB = computeK(Ax,Ay,Bx,By);
slopeCD = computeK(Cx,Cy,Dx,Dy);
slopeAC = computeK(Ax,Ay,Cx,Cy);
value = determineType(slopeAB,slopeCD,slopeAC);
printMessage(value);
return 0;
}
double computeK(double x1,double y1,double x2,double y2){
double slope;
double y,x;
//printf("I am taking y1-y2/ x1-x2 which are:/t (%d - %d) / (%d-%d)\n", y1,y2,x1,x2);
// printf("y1 - y2 = %lf\n",(y1-y2));
// printf("x1 - x2 = %lf\n",(x1-x2));
// printf("the value of y1 is: %lf\n",y1);
y = (double)y1 - y2;
x = (double)x1 - x2;
// printf("y = %lf\n", y);
// printf("x = %lf\n",x);
slope = y/x;
//slope = ((double)y1-y2)/(x1-x2);
// printf("Sloppe is %lf\n",slope);
return slope;
}
int determineType(double AB, double CD, double AC){
if(AB == CD && AB != AC && CD !=AC)
return 1;
else if(AB != CD)
return 2;
else if(AB == CD && CD == AC)
return 3;
}
void printMessage(int value){
if(value == 1)
printf("The two lines are parallel.\n");
else if(value == 2)
printf("The two lines are intersecting.\n");
else if(value ==3)
printf("The two lines are overlapping.\n");
return;
}