Code

# include <graphics.h>
# include <conio.h>
# include <iostream.h>
# include <dos.h>
void get_driver()
{
clrscr(); //clear screen
int gDriver=DETECT,gMode;
initgraph(&gDriver,&gMode,"C:\\TC\\BGI");
}

void main()
{
get_driver(); //initialize graphics
float dx,dy,x1,y1,x2,y2,m; // define variables to float which mean ( example : 11.19) values used. 
dx=dy=x1=y1=x2=y2=m=0; //set variables to zero 
cout<<"Enter value x1 ";
cin>>x1;
cout<<"Enter value y2 ";
cin>>y2;
cout<<"Enter value x2 ";
cin>>x2;
cout<<"Enter value y2 ";
cin>>y2;

cleardevice(); //clear Screen for graphics
setbkcolor(15); //set background white
while(x1<=x2 && y1<=y2)//Start Loop 
{
dx=x2-x1;
dy=y2-y1;
m=dy/dx;
delay(50);
putpixel(x1,y1,RED); //print dot

if(m<=1)
{
x1++;
y1=y1+m;
}
//end if
else
{
y1++;
x1=x1+(1/m);
}
//end else
}
//end loop
getch();
}
//end main

OUTPUT

DDA Input Values
DDA Input Values
DDA Output
DDA Output

DDA-Calculator

 

(Visited 340 times, 1 visits today)
Share with Friends :
Written by:

Leave a Reply

Your email address will not be published. Required fields are marked *