C program to draw a line.

Posted by Mangesh on April 29, 2018

/* C program to draw a line. */

Description :

In order to generate a line we need to know cordinates of two points of the line. In graphics we have inbuilt line function which accepts four parameter. line(x1,y1,x2,y2) where x1 and y2 are the x,y cordinate of first point and x2, y2 are x,y cordinate of second points.

Program :

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main() 
{
  int gdriver = DETECT, gmode;
  int x1 = 200, y1 = 200;
  int x2 = 300, y2 = 300;

  initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
  line(x1, y1, x2, y2);
  getch();
  closegraph();
}

Output :

c program to draw a line Executed and tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program for scaling of 2D object.
2 C program to tramsform 2D objects.
3 C program to draw a line.
4 C program to draw a circle.
5 C program to draw a rectangle.
6 C program for DDA algorithm to generate line.
7 C program for midpoint circle algorithm.
Latest Post
1 C program to implement Queue using linked list.
2 C program for binary search tree (BST).
3 C program to search an element in linked list.
4 C program for postorder traversal in binary tree.
5 C program for preorder traversal in binary tree.