computer graphics programs in c language with output – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sun, 14 Aug 2022 08:41:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg computer graphics programs in c language with output – Programmerbay https://programmerbay.com 32 32 C Program to Draw a Line in Computer Graphics https://programmerbay.com/program-to-draw-a-line-in-c-graphics/ https://programmerbay.com/program-to-draw-a-line-in-c-graphics/#respond Thu, 14 Jul 2022 18:02:10 +0000 https://programmerbay.com/?p=5152 There is a predefined function named line which is used to draw a line on the output screen.

It takes 4 arguments,first two parameters represent an initial point and the last two arguments are for the final points of the line.

What should you know about line function in computer graphics ?

line() is a library function used to draw a line using given coordinates. It comes under Graphic.h header file. It uses two coordinate points (x,y) as initial point and (x1,y1) as end point to draw a line on output screen.

Syntax:

void line( int x,int y,int x1,int y1);

The code given below is a simple graphic program that  draws a line.

Write a C program to draw a line in Computer Graphics?

Program:

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int x_initial,y_initial,x_final,y_final;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\n Please enter an initial coordinate of the line = ");
scanf("%d %d", &x_initial,&y_initial);
printf("\n Now, \n enter final coordinate of the line = ");
scanf("%d %d",&x_final,&y_final);
printf("\n***** LINE ******");
line(x_initial,y_initial,x_final,y_final);

getch();
closegraph();
}

 

Output:

draw a line

]]>
https://programmerbay.com/program-to-draw-a-line-in-c-graphics/feed/ 0