Saturday, 13 July 2013

Write a program to implement polygon filling




#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void fill_right(int x,int y)
{
if((getpixel(x,y)!=WHITE)&&(getpixel(x,y)!=RED))
{
putpixel(x,y,RED);
fill_right(++x,y);
x=x-1;
fill_right(x,y-1);
fill_right(x,y+1);
}
delay(1);
}
void fill_left(int x,int y)
{
if((getpixel(x,y)!=WHITE)&&(getpixel(x,y)!=RED))
{
putpixel(x,y,RED);
fill_right(--x,y);
x=x+1;
fill_right(x,y-1);
fill_right(x,y+1);
}
delay(1);
}
void main()
{
int x,y,n,i;
int get=DETECT,gm;
initgraph(&get,&gm,"c:\\tc\\bgi");
clrscr();
line(50,50,200,50);
line(200,50,200,300);
line(200,300,50,300);
line(50,300,50,50);
x=100;
y=100;
fill_right(x,y);
fill_left(x-1,y);
getch();
}



OUTPUT

Write a program to implement character stuffing


#include<stdio.h>                                                 
#include<conio.h>
#include<string.h>
#include<process.h>
void main()            
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
clrscr();
printf("enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position, Enter again :");
scanf("%d",&pos);
}
printf("enter the character\n");
ch=getche();

b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}

b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\nframe after stuffing:\n");
printf("%s",b);
getch();
}





OUTPUT