TEAM CODING-BCA

C Program for Displaying a Bouncing Ball

I
C Program for Displaying a Bouncing Ball :

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void main()
{
int x,y=0,t=400,c=1;
int gd,gm;
detectgraph(&gd,&gm);

initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
setcolor(LIGHTRED);
setfillstyle(SOLID_FILL,LIGHTRED);

for(x=40;x<600;x++)
{
cleardevice();
circle(x,y,25);
floodfill(x,y,LIGHTRED);
delay(20);

if(y>=400)
{
c=0;
t-=20;
}

if(y<(400-t))
{
c=1;
}

y=y+(c?15:-15);
}

getch();
closegraph();
}

Output

Output

Output



No comments:

Post a Comment