-
Notifications
You must be signed in to change notification settings - Fork 0
/
LINEP.C
60 lines (45 loc) · 865 Bytes
/
LINEP.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
// A program in C to print a line using putpixel() function.
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
int main()
{
int gd=DETECT, gm;
float x,y,x1,y1,x2,y2,m,c,i;
printf("X1:");
scanf("%f",&x1);
printf("Y1:");
scanf("%f",&y1);
printf("X2:");
scanf("%f",&x2);
printf("Y2:");
scanf("%f",&y2);
m=(y2-y1)/(x2-x1);
c=y1-(m*x1);
initgraph(&gd,&gm,"c:\\tc\\bgi");
line(x1,y1,x2,y2);
if(x2<x1)
{
x=x1;
x1=x2;
x2=x;
y=y1;
y1=y2;
y2=y;
for(i=x1;i<=x2;i++)
{
putpixel(i,(i*m)+c,RED);
}
}
else
{
for(i=x1;i<=x2;i++)
{
putpixel(i,(i*m)+c,RED);
}
}
outtextxy(0,420,"Coordinates of the line are : (x1,y1),(x2,y2)");
outtextxy(0,430,"Slope of the line is m.");
getch();
closegraph();
}