SlideShare a Scribd company logo
1 of 3
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
main()
{
int n,i,j,k,gd,gm,dy,dx;
int x,y,temp;
int a[20][2],xi[20];
float slope[20];
clrscr();
printf("nntEnter the no. of edges of polygon : ");
scanf("%d",&n);
printf("nntEnter the cordinates of polygon :nnn ");
for(i=0;i<n;i++)
{
printf("tX%d Y%d : ",i,i);
scanf("%d %d",&a[i][0],&a[i][1]);
}
a[n][0]=a[0][0];
a[n][1]=a[0][1];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:tcbgi");
/*- draw polygon -*/
for(i=0;i<n;i++)
{
line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
}
getch();
for(i=0;i<n;i++)
{
dy=a[i+1][1]-a[i][1];
dx=a[i+1][0]-a[i][0];
if(dy==0) slope[i]=1.0;
if(dx==0) slope[i]=0.0;
if((dy!=0)&&(dx!=0)) /*- calculate inverse slope -*/
{
slope[i]=(float) dx/dy;
}
}
for(y=0;y< 480;y++)
{
k=0;
for(i=0;i<n;i++)
{
if( ((a[i][1]<=y)&&(a[i+1][1]>y))||
((a[i][1]>y)&&(a[i+1][1]<=y)))
{
xi[k]=(int)(a[i][0]+slope[i]*(y-a[i][1]));
k++;
}
}
for(j=0;j<k-1;j++) /*- Arrange x-intersections in order -*/
for(i=0;i<k-1;i++)
{
if(xi[i]>xi[i+1])
{
temp=xi[i];
xi[i]=xi[i+1];
xi[i+1]=temp;
}
}
setcolor(35);
for(i=0;i<k;i+=2)
{
line(xi[i],y,xi[i+1]+1,y);
getch();
}
}
}

More Related Content

What's hot (20)

Bcsl 033 data and file structures lab s1-2
Bcsl 033 data and file structures lab s1-2Bcsl 033 data and file structures lab s1-2
Bcsl 033 data and file structures lab s1-2
 
Numeros primos
Numeros primosNumeros primos
Numeros primos
 
N primo clase programa
N primo clase programaN primo clase programa
N primo clase programa
 
C Program : Sorting : Bubble,
C Program : Sorting : Bubble, C Program : Sorting : Bubble,
C Program : Sorting : Bubble,
 
Fcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt ChartFcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt Chart
 
Quick sort
Quick sortQuick sort
Quick sort
 
Cpro
CproCpro
Cpro
 
Tugas4
Tugas4Tugas4
Tugas4
 
Wave ECG
Wave ECGWave ECG
Wave ECG
 
listing output program C
listing output program Clisting output program C
listing output program C
 
Dado un vector imprimir cuantas vocales tiene
Dado un vector imprimir cuantas vocales tieneDado un vector imprimir cuantas vocales tiene
Dado un vector imprimir cuantas vocales tiene
 
Bcsl 033 data and file structures lab s4-3
Bcsl 033 data and file structures lab s4-3Bcsl 033 data and file structures lab s4-3
Bcsl 033 data and file structures lab s4-3
 
Rafaeltorres
RafaeltorresRafaeltorres
Rafaeltorres
 
contoh Program C++ tentang fungsi for
contoh Program C++ tentang fungsi forcontoh Program C++ tentang fungsi for
contoh Program C++ tentang fungsi for
 
Info clasa
Info clasaInfo clasa
Info clasa
 
Ejercicios.
Ejercicios. Ejercicios.
Ejercicios.
 
Memoria dinámica ejercicio
Memoria dinámica ejercicioMemoria dinámica ejercicio
Memoria dinámica ejercicio
 
Sources
SourcesSources
Sources
 
07 5 반복문(break,contine).key
07 5 반복문(break,contine).key07 5 반복문(break,contine).key
07 5 반복문(break,contine).key
 
Cg lab cse-vii
Cg lab cse-viiCg lab cse-vii
Cg lab cse-vii
 

Viewers also liked

3Com 3C17260-NEW
3Com 3C17260-NEW3Com 3C17260-NEW
3Com 3C17260-NEWsavomir
 
Need for reliable statistics
Need for reliable statisticsNeed for reliable statistics
Need for reliable statisticsM S Siddiqui
 
3Com 3CNJ225FX-SC
3Com 3CNJ225FX-SC3Com 3CNJ225FX-SC
3Com 3CNJ225FX-SCsavomir
 
정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...
정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...
정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...블랙 핑크
 
The Student Survival sMOOC - Designing and Piloting a course in partnership w...
The Student Survival sMOOC - Designing and Piloting a course in partnership w...The Student Survival sMOOC - Designing and Piloting a course in partnership w...
The Student Survival sMOOC - Designing and Piloting a course in partnership w...Carl Sykes
 
TEST 2013 INFORMATICA
TEST 2013 INFORMATICATEST 2013 INFORMATICA
TEST 2013 INFORMATICArosucamelia
 
¿Cómo atacan los patógenos a las plantas?
¿Cómo atacan los patógenos a las plantas?¿Cómo atacan los patógenos a las plantas?
¿Cómo atacan los patógenos a las plantas?Sabrina Guamán
 
New microsoft power point presentation
New microsoft power point presentationNew microsoft power point presentation
New microsoft power point presentationHimanshu Maurya
 

Viewers also liked (11)

3Com 3C17260-NEW
3Com 3C17260-NEW3Com 3C17260-NEW
3Com 3C17260-NEW
 
Need for reliable statistics
Need for reliable statisticsNeed for reliable statistics
Need for reliable statistics
 
3Com 3CNJ225FX-SC
3Com 3CNJ225FX-SC3Com 3CNJ225FX-SC
3Com 3CNJ225FX-SC
 
정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...
정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...
정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...
 
Oficio
OficioOficio
Oficio
 
Crise democracia fascismos
Crise democracia fascismosCrise democracia fascismos
Crise democracia fascismos
 
compassionate care car pool to school
compassionate care car pool to schoolcompassionate care car pool to school
compassionate care car pool to school
 
The Student Survival sMOOC - Designing and Piloting a course in partnership w...
The Student Survival sMOOC - Designing and Piloting a course in partnership w...The Student Survival sMOOC - Designing and Piloting a course in partnership w...
The Student Survival sMOOC - Designing and Piloting a course in partnership w...
 
TEST 2013 INFORMATICA
TEST 2013 INFORMATICATEST 2013 INFORMATICA
TEST 2013 INFORMATICA
 
¿Cómo atacan los patógenos a las plantas?
¿Cómo atacan los patógenos a las plantas?¿Cómo atacan los patógenos a las plantas?
¿Cómo atacan los patógenos a las plantas?
 
New microsoft power point presentation
New microsoft power point presentationNew microsoft power point presentation
New microsoft power point presentation
 

More from Sonia Pahuja

numerical method solutions
numerical method solutionsnumerical method solutions
numerical method solutionsSonia Pahuja
 
Bisection method solved questions
Bisection method solved questionsBisection method solved questions
Bisection method solved questionsSonia Pahuja
 
raster and random scan
raster and random scanraster and random scan
raster and random scanSonia Pahuja
 
Graphics exercise (b.tech)
Graphics exercise (b.tech)Graphics exercise (b.tech)
Graphics exercise (b.tech)Sonia Pahuja
 
Graphics exercise (b.tech)
Graphics exercise (b.tech)Graphics exercise (b.tech)
Graphics exercise (b.tech)Sonia Pahuja
 
Surajkund Mella Faridabad
Surajkund Mella FaridabadSurajkund Mella Faridabad
Surajkund Mella FaridabadSonia Pahuja
 
Determinant Matlab Code
Determinant Matlab CodeDeterminant Matlab Code
Determinant Matlab CodeSonia Pahuja
 
CODE Data Structures
CODE Data StructuresCODE Data Structures
CODE Data StructuresSonia Pahuja
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMSonia Pahuja
 
Introduction to sets
Introduction to setsIntroduction to sets
Introduction to setsSonia Pahuja
 

More from Sonia Pahuja (14)

numerical method solutions
numerical method solutionsnumerical method solutions
numerical method solutions
 
Bisection method solved questions
Bisection method solved questionsBisection method solved questions
Bisection method solved questions
 
raster and random scan
raster and random scanraster and random scan
raster and random scan
 
Graphics exercise (b.tech)
Graphics exercise (b.tech)Graphics exercise (b.tech)
Graphics exercise (b.tech)
 
graphics notes
graphics notesgraphics notes
graphics notes
 
Graphics exercise (b.tech)
Graphics exercise (b.tech)Graphics exercise (b.tech)
Graphics exercise (b.tech)
 
Surajkund Mella Faridabad
Surajkund Mella FaridabadSurajkund Mella Faridabad
Surajkund Mella Faridabad
 
Business Ethics
Business Ethics Business Ethics
Business Ethics
 
Determinant Matlab Code
Determinant Matlab CodeDeterminant Matlab Code
Determinant Matlab Code
 
Gaussel Method
Gaussel MethodGaussel Method
Gaussel Method
 
CODE Data Structures
CODE Data StructuresCODE Data Structures
CODE Data Structures
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
 
Introduction to sets
Introduction to setsIntroduction to sets
Introduction to sets
 
Data Link Control
Data Link ControlData Link Control
Data Link Control
 

Scanfill polygon