Sunday, 18 November 2012

Program To Implement A Line Using Slope Intercept Formula


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
float m,x1,y1,x2,y2;
int x,y;
int gdriver=DETECT,gmode,gerror;
clrscr();
printf(" PROGRAM FOR THE LINE INTERCEPT \n");
printf(" Enter the value of x1");
scanf("%f",&x1);
printf(" Enter the value of y1");
scanf("%f",&y1);
printf(" Enter the value of x2");
scanf("%f",&x2);
printf(" Enter the value of y2");
scanf("%f",&y2);
initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi");
m=(y2-y1)/(x2-x1);
for(x=1;x<=x2;x++)
{
y=m*(x-x1)+y1;
putpixel(x,y,15);
delay(50);
}
getch();
closegraph();
}

4 comments: