Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
482 B
2
Indexable
Never
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
int gd=DETECT,gm;
void main()
{
	
	int x,y,x1,y1=0;
	int i=1;
	int p=0;
	printf("Enter the initial and final points:");
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&x1);
	scanf("%d",&y1);
	int dx,dy=0;
	dx=x1-x;
	dy=y1-y;
	p=2*dy-dx;
	initgraph(&gd,&gm,NULL);
	while(i<=dx)
	{
		if(p>0)
		{
			x+=1;
			y+=1;
			p+=2*dy-2*dx;
		}
		else
		{
			x+=1;
			p+=2*dy;
		}
		putpixel(x,y,i);
		i++;
	}
	getch();
	closegraph();
}