-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleDDAlineDrawingAlgo.c
62 lines (53 loc) · 1.1 KB
/
simpleDDAlineDrawingAlgo.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
#include<stdio.h>
int main()
{
float x1,y1,x2,y2,m,i,j,diff_of_x,diff_of_y;
printf("Enter the value of X1 : ");
scanf("%f",&x1);
printf("Enter the value of Y1 : ");
scanf("%f",&y1);
printf("Enter the value of X2 : ");
scanf("%f",&x2);
printf("Enter the value of Y2 : ");
scanf("%f",&y2);
diff_of_x=x2-x1;
diff_of_y=y2-y1;
m=diff_of_y/diff_of_x;
if(m>0 && m<=1)
{
while(x1<=x2 && y1<=y2)
{
x1++;
y1=y1+m;
printf("%f %f \n",x1,y1);
}
}
else if(m>1)
{
while(x1<=x2 && y1<=y2)
{
x1=x1+(1/m);
y1++;
printf("%f %f",x1,y1);
}
}
else if(m>-1 && m<=0)
{
while(x1>=x2 && y1>=y2)
{
x1--;
y1=y1-m;
printf("%f %f",x1,y1);
}
}
else if(m<-1)
{
while(x1>=x2 && y1>=y2)
{
x1=x1-(1/m);
y1--;
printf("%f %f",x1,y1);
}
}
return 0;
}