-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbs_line.cpp
More file actions
39 lines (36 loc) · 756 Bytes
/
Copy pathbs_line.cpp
File metadata and controls
39 lines (36 loc) · 756 Bytes
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
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
void drawline(int x0, int y0, int x1, int y1)
{
int dx, dy, p, x, y;
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1)
{
if(p>=0)
{
cout<<x<<" "<<y<<endl;
y=y+1;
p=p+2*dy-2*dx;
}
else
{
cout<<x<<" "<<y<<endl;
p=p+2*dy;}
x=x+1;
}
}
int main()
{
int x0,y0,x1,y1;
printf("Enter co-ordinates of first point: ");
scanf("%d%d", &x0, &y0);
printf("Enter co-ordinates of second point: ");
scanf("%d%d", &x1, &y1);
drawline(x0, y0, x1, y1);
return 0;
}