Name: Saad Haji Enrollment no: 23111590411 Class : C03KB
Batch: 1 Subject: CGR Practical: 3
Program :
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
void main(){
int x,y,x1,y1,x2,y2,p,i;
int dx, dy;
int gd = DETECT, gm;
clrscr();
printf("\n Enter the value for starting point of line: "); scanf("%d%d", &x1, &y1);
printf("\n Enter the value for ending point: "); scanf("%d%d",&x2,y2);
dx = abs (x2 x1);
dy = abs (y2 - y1);
x = x1;
y = y1;
i = 0;
= 2 * (dy dx);
initgraph (&gd, & gm, "C:\\TURBOC3\/BGI");
while (i<=dx){
putpixel(x,y,WHITE);
if (p<=0){
x = x + 1;
p = p + 2 dy;
}
else{
x = x + 1;
y = y + 1;
p = p + 2 dy
}
i++;
delay(25);
initgraph (&g, & gm, "C:\\TURBOC3\\BGI");
while (i<=dx){
putpixel(x,y,WHITE);
if (p<=0){
x = x + 1;
p = p + 2 dy;
}
else{
x = x + 1;
y = y + 1;
p = p + 2 dy - 2 * dx;
}
i++;
delay(25);
}
getch();
closegraph();
}
Output :