0% found this document useful (0 votes)
41 views4 pages

Execute A C Program To Move A Box From Left To Right or Top To Bottom On User's Input Using DDA Algorithm. Source Code

The C program uses the Digital Differential Analyzer (DDA) algorithm to move a box from left to right or top to bottom based on user input. Functions are defined to move the box in each of the four directions and a select function uses a switch statement to call the appropriate function based on the user's choice.

Uploaded by

Every Thing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views4 pages

Execute A C Program To Move A Box From Left To Right or Top To Bottom On User's Input Using DDA Algorithm. Source Code

The C program uses the Digital Differential Analyzer (DDA) algorithm to move a box from left to right or top to bottom based on user input. Functions are defined to move the box in each of the four directions and a select function uses a switch statement to call the appropriate function based on the user's choice.

Uploaded by

Every Thing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Execute a C program to move a box from left to right or top to bottom on user’s input

using DDA Algorithm.


Source Code :

#include<graphics.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
#include<stdio.h>
int x,y;
int flag=0;
void right()
{
while(flag==0)
{
for(x=0;x<=420;x=x+10)
{
cleardevice();
rectangle(50+x,100,150+x,200);
delay(100);
}
flag=1;
if(flag==1)
exit(0);
}
}
void left()
{
while(flag==0)
{
for(x=0;x<=360;x=x+10)
{
cleardevice();
rectangle(400-x,200,500-x,300);
delay(100);
}
flag=1;
if(flag==1)
exit(0);
}
}
void top()
{

SHOBHA 180938
while(flag==0)
{
for(y=0;y<=300;y=y+10)
{
cleardevice();
rectangle(150,300-y,250,400-y);
delay(100);
}
flag=1;
if(flag==1)
exit(0);
}
}
void down()
{
while(flag==0)
{
for(y=0;y<=300;y=y+10)
{
cleardevice();
rectangle(150,50+y,250,150+y);
delay(100);
}
flag=1;
if(flag==1)
exit(0);
}
}
void select()
{
int ch;
clrscr();
do
{
printf("\n\t1.left to right\n\t2.right to left\n\t3.top to down\n\t4.down to
top\n\t5.exit\n");
printf("\tenter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:right();
break;
case 2:left();

SHOBHA 180938
break;
case 3:down();
break;
case 4:top();
break;
case 5:exit(0);
default:printf("Please enter valid choice..");
}
}while(1);
}
void main()
{
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"c://turboc3//bgi");
setbkcolor(BLACK);
setcolor(YELLOW);
select();
getch();
closegraph();
}

Output :

SHOBHA 180938
SHOBHA 180938

You might also like