Sunday 23 March 2014

Boundary Fill Algorithm Using C

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

void boundryFill(int, int, int, int);
int midx=319, midy=239;

void main()
{
int gdriver=DETECT, gmode, x,y,r;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
cleardevice();
printf("Enter the Center of circle (X,Y) : ");
scanf("%d %d",&x,&y);
printf("Enter the Radius of circle R : ");
scanf("%d",&r);
circle(midx+x,midy-y,r);
getch();
boundryFill(midx+x,midy-y,13,15);
getch();
closegraph();
}
void boundryFill(int x, int y, int fill, int boundry)
{
if((getpixel(x,y)!= fill) && (getpixel(x,y) != boundry))
{
putpixel(x,y,fill);
delay(5);
boundryFill(x+1,y,fill,boundry);
boundryFill(x-1,y,fill,boundry);
boundryFill(x,y+1,fill,boundry);
boundryFill(x,y-1,fill,boundry);
}
}

Flood Fill Algorithm Using C

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

void flood(int,int,int);

void main()
{

int gd=DETECT,gm;
int ch,x,y,bc,fc;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
printf("Enter boundry color:");
scanf("%d",&bc);
setcolor(bc);
rectangle(250,200,300,250);
x=280;
y=240;
flood(x,y,bc);
getch();
closegraph();
}
void flood(int x,int y,int bc)
{
if(getpixel(x,y)!=bc)
{
putpixel(x,y,bc);
flood(x+1,y,bc);
flood(x,y+1,bc);
flood(x-1,y,bc);
flood(x,y-1,bc);
}
}

Thursday 6 March 2014

Tower Of Hanoi Using Backtracking in c++

#include<iostream.h>

#include<conio.h> 

void tower(int,char,char,char); 

void main()

{

int n; 

clrscr();

cout<<"enter the disk number :  ";

cin>>n;tower(n,'A','C','B'); 

getch();

void tower(int n,char from,char to,char aux)

{

if(n==1)
    {

    cout<<endl<<"move 1 from peg "<<from<<" to "<<to;return;

   }

tower(n-1,from,aux,to);

cout<<endl<<"move "<<n<<" from peg "<<from<<" to "<<to;

tower(n-1,aux,to,from);

}


Tuesday 4 March 2014

Draw Arc Using C

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
#include<dos.h>
void main()
{
        int gd=DETECT,gm=0;
initgraph(&gd,&gm,"c:\\tc\\bgi");
       arc(110, 110, 0, 145, 55);
       /*
       arc(a,b,c,d,e);
       a= x
       b=y
       c=start angle
       d= end angle
       e=radius of arc.
       */
       getch();
       closegraph();
}

Draw Rectangle Using C

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm=0;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
     int midx,midy,x,y;
     x=getmaxx();
     y=getmaxy();
     midx=x/2;
     midy=y/2;
     rectangle(midx-110,midy-110,midx+110,midy+110);
     getch();
     closegraph();
}

Draw Circle Using C

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
        gm=0;
        circle(250,250,100);
       /*  circle(a,b,c);
      a=X axis element
      b=Y axis element
      c=radius
       */
       getch();
       closegraph();
}

Horizontal Line And Vertical Line of Center Of Screen Using C

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm,maxx,maxy,midx,midy;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
        maxx=getmaxx();
        maxy=getmaxy();
        midx=maxx/2;
        midy=maxy/2;
        line(0,midy,midx,maxy);
        line(midx,0,midx,maxy);
getch();
closegraph();
}


////////////////////////////OUTPUT//////////////////////////////